简体   繁体   中英

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. 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).

*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?

将两个变量作为参数添加到函数中。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM