[英]Global vars and function in an include file PHP
I am trying to resize an image's size and then putting it in a FancyBox. 我正在尝试调整图像的大小,然后将其放入FancyBox中。 I've managed to do so in another page and I imitated it to the other page, and the functions wont work.
我设法在另一页上这样做,并且将其模仿到另一页上,并且该功能将无法正常工作。
This is the code in the not working page (it has 2 vars for width and height, and the resizeImage function gets to them by declaring "global ;", however it wont work). 这是不工作页面中的代码(它的宽度和高度有2个var,而resizeImage函数通过声明“ global;”来获取它们,但是它不起作用)。
*Note- both pages: the one that's working and the one that doesn't are on the same folder so all paths are the same. *请注意-这两页:有效的页面和不在同一文件夹的页面,因此所有路径都相同。
include("Include/FunctionsPHP.php"); //Includes the ResizeImage functions
$outputHeight;
$outputWidth;
$index=$row["nIndex"];
$picture="products/pictures/{$row["sPicture"]}";
ResizeImage(450,400,$picture);
And this is the Include file: 这是包含文件:
function ResizeImage($maxWidth,$maxHeight,$picture)
{
GLOBAL $outputWidth;
GLOBAL $outputHeight;
$size = getimagesize($picture);
if ($size) {
$imageWidth = $size[0];
$imageHeight = $size[1];
$wRatio = $imageWidth / $maxWidth;
$hRatio = $imageHeight / $maxHeight;
$maxRatio = max($wRatio, $hRatio);
$outputWidth = $imageWidth / $maxRatio;
$outputHeight = $imageHeight / $maxRatio;
echo $outputHeight."\t";
echo $outputWidth;
}
}
?>
Any ideas? 有任何想法吗?
将两个变量作为参数添加到函数中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.