简体   繁体   English

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

[英]Passing an Variable from one PHP File to another

I'm working on an image resizer, to create thumbnails for my page. 我正在使用图像大小调整器,以为页面创建缩略图。 The resizer works on principle of include a DIRECT link to the image. 调整大小器的工作原理是包含指向图像的DIRECT链接。 But what I want to do is put in the PHP Variable in the URL string, so that it points to that file and resizes it accordingly. 但是我要做的是将URL字符串中的PHP变量放入,以便它指向该文件并相应地调整其大小。

My code is as follows : 我的代码如下:

<img src="thumbnail.php?image=<?php echo $row_select_property['image_url']; ?>

Image Resize : 图片尺寸调整:

 <?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); 
    ?>

What I am trying to do is pass on the variable "image=" to the Thumbnail script. 我想做的是将变量“ image =”传递给Thumbnail脚本。 At the moment I am passing it through the URL string, but it doesnt seem to load the graphic. 目前,我正在通过URL字符串传递它,但它似乎并未加载图形。

I'll try expand on this more, should you have questions as I am finding it a little difficult to explain. 如果您有任何疑问,我会尝试进一步扩展,因为我觉得这很难解释。

Thanks in advance. 提前致谢。

I suspect at least part of the problem is that your existing... 我怀疑至少部分问题是您现有的...

$image = '$_GET[image_url]'; 

...line is creating a text string, rather than getting the contents of the 'image_url' query string. ...行正在创建文本字符串,而不是获取'image_url'查询字符串的内容。 Additionally, your passing in the image name as "?image=" in the query string, so you should simply use "image", not "image_url". 此外,您在查询字符串中将图像名称作为“?image =“传递,因此您应该只使用“ image”,而不是“ image_url”。

As such, changing this to... 因此,将其更改为...

$image = $_GET['image'];

...should at least move things along. ...至少应该顺其自然。

$image = '$_GET[image_url]';

应该

$image = $_GET['image'];

Change it 更改

 $image = '$_GET[image_url]'; 

to

 $image = $_GET['image']; 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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