Jump to content

Problem with passing variable in img src


emancipator

Recommended Posts

Here is the code.

 

//The main php file
<?php
echo "<img src='imageScript.php?$imgurl=" . $url . "'/>"
?>

 

imgScript.php contains a script that will operate on an image.

I am trying to operate on image $url (in this case) then display it using the img tag.

 

The problem I am having is the img tag displays using the url containing ?imgurl= instead of processing it through the script first.

 

I can't think of an solution to this. I am sure I am just missing something simple, but don't know what it is. Any ideas?

Link to comment
https://forums.phpfreaks.com/topic/83614-problem-with-passing-variable-in-img-src/
Share on other sites

Thanks for your reply. You meant placing $_GET at the start of the script? It is at the start...

 

My problem is the img src isn't interpreting $imgurl= ...instead, its taking that as a part of the url. (ie. when I check the location of the image, it literally displays as "/imageScript1.php?pic=images/whatever.jpg"

 

comments?

I'm assuming imageScript.php actually manipulates the image in some noticeable way SUCCESSFULLY? Resizes it or something?

 

echo "<img src='imageScript.php?$imgurl=" . $url . "'/>"

 

I'm pretty new at this myself but doesn't the $ in the url mess things up? shouldn't it just be:

 

echo "<img src='imageScript.php?imgurl=" . $url . "'/>"

 

I think that's the 'right way' to pass a variable in a url as far as i know...

Oops..sorry that $ shouldn't be there. The problem still exist, "?imgurl=" is still a part of the image url...

 

And yes, the script works by itself (I've tested it)

 

The script still doesn't operate on the image.

 

Here is the code

 

Main page

 

<?php
$images = array ('a.JPG', 'b.JPG', 'c.JPG');

foreach ($images as $picture)
{
     echo "<img src='imageScript1.php?pic=" . $picture . "'>";
}
?>

 

Script

$picToResize = $_GET['pic']

$src = imagecreatefromjpeg($picToResize);

// resize code here
// ... 
// end of resize code


        ImageJPEG ($thumb, null, 75);

imagedestroy($src);
imagedestroy($thumb);

<img src='imageScript1.php?pic=a.JPG'>

<img src='imageScript1.php?pic=b.JPG'>

<img src='imageScript1.php?pic=c.JPG'>

 

<?php
$images = array ('a.JPG', 'b.JPG', 'c.JPG');

foreach ($images as $picture)
{
     echo "<img src='imageScript1.php?pic=" . $picture . "'>";
}
?>

 

works correctly m8...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.