将变量从一个PHP文件传递到另一个PHP文件

Stu*_*ett 0 php

我正在使用图像缩放器,为我的页面创建缩略图.缩放器的工作原理是包括指向图像的DIRECT链接.但我想要做的是在URL字符串中放入PHP变量,以便它指向该文件并相应地调整它的大小.

我的代码如下:

<img src="thumbnail.php?image=<?php echo $row_select_property['image_url']; ?>
Run Code Online (Sandbox Code Playgroud)

图像大小调整:

 <?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); 
    ?>
Run Code Online (Sandbox Code Playgroud)

我想要做的是将变量"image ="传递给Thumbnail脚本.目前我正在通过URL字符串传递它,但它似乎没有加载图形.

我会尝试进一步扩展,如果你有问题,我发现它有点难以解释.

提前致谢.

Joh*_*ker 6

我怀疑至少部分问题是你现有的......

$image = '$_GET[image_url]'; 
Run Code Online (Sandbox Code Playgroud)

... line正在创建文本字符串,而不是获取'image_url'查询字符串的内容.此外,您在查询字符串中传递图像名称为"?image =",因此您应该只使用"image",而不是"image_url".

因此,将此更改为......

$image = $_GET['image'];
Run Code Online (Sandbox Code Playgroud)

......至少应该改变一切.