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

Link to comment
Share on other sites

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...

Link to comment
Share on other sites

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

Link to comment
Share on other sites

<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...

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.