簡體   English   中英

包含文件PHP中的全局變量和函數

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM