emancipator Posted December 29, 2007 Share Posted December 29, 2007 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? Quote Link to comment https://forums.phpfreaks.com/topic/83614-problem-with-passing-variable-in-img-src/ Share on other sites More sharing options...
revraz Posted December 29, 2007 Share Posted December 29, 2007 You have to check if $_GET['imgurl'] is set at the start of your code. If it is, process it, if not, skip it. Quote Link to comment https://forums.phpfreaks.com/topic/83614-problem-with-passing-variable-in-img-src/#findComment-425387 Share on other sites More sharing options...
emancipator Posted December 29, 2007 Author Share Posted December 29, 2007 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? Quote Link to comment https://forums.phpfreaks.com/topic/83614-problem-with-passing-variable-in-img-src/#findComment-425529 Share on other sites More sharing options...
revraz Posted December 30, 2007 Share Posted December 30, 2007 You only posted 1 line of code, kinda hard to help you without seeing anything else. Quote Link to comment https://forums.phpfreaks.com/topic/83614-problem-with-passing-variable-in-img-src/#findComment-425577 Share on other sites More sharing options...
codebyren Posted December 30, 2007 Share Posted December 30, 2007 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... Quote Link to comment https://forums.phpfreaks.com/topic/83614-problem-with-passing-variable-in-img-src/#findComment-425668 Share on other sites More sharing options...
emancipator Posted December 30, 2007 Author Share Posted December 30, 2007 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); Quote Link to comment https://forums.phpfreaks.com/topic/83614-problem-with-passing-variable-in-img-src/#findComment-425758 Share on other sites More sharing options...
redarrow Posted December 30, 2007 Share Posted December 30, 2007 try this please at the top off your page cheers.... <?php if($_GET['imgurl']){ $u="<img src='imageScript.php?imgurl='".$url."' />"; echo $u; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/83614-problem-with-passing-variable-in-img-src/#findComment-425769 Share on other sites More sharing options...
redarrow Posted December 30, 2007 Share Posted December 30, 2007 <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... Quote Link to comment https://forums.phpfreaks.com/topic/83614-problem-with-passing-variable-in-img-src/#findComment-425773 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.