[英]Global vars and function in an include file PHP
我正在尝试调整图像的大小,然后将其放入FancyBox中。 我设法在另一页上这样做,并且将其模仿到另一页上,并且该功能将无法正常工作。
这是不工作页面中的代码(它的宽度和高度有2个var,而resizeImage函数通过声明“ global;”来获取它们,但是它不起作用)。
*请注意-这两页:有效的页面和不在同一文件夹的页面,因此所有路径都相同。
include("Include/FunctionsPHP.php"); //Includes the ResizeImage functions
$outputHeight;
$outputWidth;
$index=$row["nIndex"];
$picture="products/pictures/{$row["sPicture"]}";
ResizeImage(450,400,$picture);
这是包含文件:
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;
}
}
?>
有任何想法吗?
将两个变量作为参数添加到函数中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.