[英]Passing an Variable from one PHP File to another
我正在使用圖像大小調整器,以為頁面創建縮略圖。 調整大小器的工作原理是包含指向圖像的DIRECT鏈接。 但是我要做的是將URL字符串中的PHP變量放入,以便它指向該文件並相應地調整其大小。
我的代碼如下:
<img src="thumbnail.php?image=<?php echo $row_select_property['image_url']; ?>
圖片尺寸調整:
<?php
// Resize Image To A Thumbnail
// The file you are resizing
$image = '$_GET[image_url]';
//This will set our output to 45% of the original size
$size = 0.45;
// This sets it to a .jpg, but you can change this to png or gif
header('Content-type: image/jpeg');
// Setting the resize parameters
list($width, $height) = getimagesize($image);
$modwidth = $width * $size;
$modheight = $height * $size;
// Creating the Canvas
$tn= imagecreatetruecolor($modwidth, $modheight);
$source = imagecreatefromjpeg($image);
// Resizing our image to fit the canvas
imagecopyresized($tn, $source, 0, 0, 0, 0, $modwidth, $modheight, $width, $height);
// Outputs a jpg image, you could change this to gif or png if needed
imagejpeg($tn);
?>
我想做的是將變量“ image =”傳遞給Thumbnail腳本。 目前,我正在通過URL字符串傳遞它,但它似乎並未加載圖形。
如果您有任何疑問,我會嘗試進一步擴展,因為我覺得這很難解釋。
提前致謝。
我懷疑至少部分問題是您現有的...
$image = '$_GET[image_url]';
...行正在創建文本字符串,而不是獲取'image_url'查詢字符串的內容。 此外,您在查詢字符串中將圖像名稱作為“?image =“傳遞,因此您應該只使用“ image”,而不是“ image_url”。
因此,將其更改為...
$image = $_GET['image'];
...至少應該順其自然。
$image = '$_GET[image_url]';
應該
$image = $_GET['image'];
更改
$image = '$_GET[image_url]';
至
$image = $_GET['image'];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.