laanes Posted September 6, 2010 Share Posted September 6, 2010 Hi, On a website, there are products nicely listed with name, description, product code, price and a thumbnail etc. Now, if you click on a picture thumbnail, a new page called prodwin.php in a new window opens with the product code and for some reason, there is a "no picture available" alt image for every product. The line of code in it: <td colspan="2"><?php if(file_exists("../pics_p/".$HTTP_GET_VARS["PCode"].".jpg")){?><img src="../pics_p/<?php echo $HTTP_GET_VARS["PCode"] ?>.jpg" alt="Product Picture" galleryimg="no"><?php }else{?><img src="../imgz/nopic.jpg" alt="No Picture Available" width="306" height="200" galleryimg="no"><?php }?></td> The URL of that page looks like this: http://www.lock-tech.co.uk/scrptz/prodwin.php?SCode=CHL8K119S&PCode=CHL8K119S&PDescription=+DOOR%20PATIO%20LOCK&KEY%20SATIN&thePrice=%A328.52%20/%20EA On the other hand, when you click on the product name, it loads a different page called g_browse.php and the product image is nicely there. The line of code in it: <td height="366" colspan="2" valign="top"><?php if(file_exists("pics_p/".$array[$getVars["index"]]["PCode"].".jpg")){?><img src="pics_p/<?php echo $array[$getVars["index"]]["PCode"] ?>.jpg" alt="Product Picture" galleryimg="no"><?php }else{?><img src="imgz/nopic.jpg" alt="No Picture Available" width="306" height="200" galleryimg="no"><?php }?></td> $HTTP_GET_VARS["PCode"].".jpg" - Product code + .jpg will give the image name in pics_p folder. a JavaScript block which might also be relavant: function prodWindow(SCode, PCode, PDescription, thePrice) { var xPos=(screen.availWidth/2)-490; var yPos=(screen.availHeight/2)-116; var s=",top="+yPos+",left="+xPos; var win=open("scrptz/prodwin.php?SCode="+SCode+"&PCode="+PCode+"&PDescription="+PDescription+"&thePrice="+thePrice,'product', "toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=no,copyhistory=no,scrollbars=no,height=414,width=316"+s); win.focus(); } Hope someone spots the problem. Regards, laanes Quote Link to comment https://forums.phpfreaks.com/topic/212652-how-to-display-an-image-in-a-popup-window/ Share on other sites More sharing options...
Adam Posted September 6, 2010 Share Posted September 6, 2010 Try reversing the if statement with "!" at the start of the expression, if the image displays it's probably a permissions problem. Quote Link to comment https://forums.phpfreaks.com/topic/212652-how-to-display-an-image-in-a-popup-window/#findComment-1107795 Share on other sites More sharing options...
rwwd Posted September 6, 2010 Share Posted September 6, 2010 Just a comment really for future reference - as of php4.1.0 $HTTP_GET_VARS, $HTTP_POST_VARS and $HTTP_POST_FILES was/is deprecated. The preferred method of accessing these global values is like so:- $_POST: http://www.php.net/manual/en/reserved.variables.post.php $_GET: http://www.php.net/manual/en/reserved.variables.get.php $_FILES: http://www.php.net/manual/en/reserved.variables.files.php Not forgetting that this array ($_FILES) has five or six different parameters to it too, very helpful they are:- (Shamelessly pinched from the php.net website...) [name] => MyFile.jpg [type] => image/jpeg [tmp_name] => /tmp/php/php6hst32 [error] => UPLOAD_ERR_OK => 98174 Just thought I should highlight this point as I am seeing this becoming more and more popular as a coding error (fails when people upgrade to V5) Cheers, Rw Quote Link to comment https://forums.phpfreaks.com/topic/212652-how-to-display-an-image-in-a-popup-window/#findComment-1107804 Share on other sites More sharing options...
laanes Posted September 6, 2010 Author Share Posted September 6, 2010 Try reversing the if statement with "!" at the start of the expression, if the image displays it's probably a permissions problem. Ok, added the !, now it doesn't display the no image available alt image either. In case i have added the ! in a wrong place maybe, the line looks like this now: <td colspan="2"><?php if(!file_exists("../pics_p/".$_GET["PCode"].".jpg")){?><img src="../pics_p/<?php echo $_GET["PCode"] ?>.jpg" alt="Product Picture" galleryimg="no"><?php }else{?><img src="../imgz/nopic.jpg" alt="No Picture Available" width="306" height="200" galleryimg="no"><?php }?></td> Quote Link to comment https://forums.phpfreaks.com/topic/212652-how-to-display-an-image-in-a-popup-window/#findComment-1107859 Share on other sites More sharing options...
Adam Posted September 6, 2010 Share Posted September 6, 2010 Yeah that's right. So the image is broken? That'll explain why file_exists() was returning false.. Quote Link to comment https://forums.phpfreaks.com/topic/212652-how-to-display-an-image-in-a-popup-window/#findComment-1107860 Share on other sites More sharing options...
laanes Posted September 6, 2010 Author Share Posted September 6, 2010 Yeah that's right. So the image is broken? That'll explain why file_exists() was returning false.. It is not for one specific image, none of them are showing up. I checked the folder permissions because you mentioned it earlier, the pictures folder is readable. Quote Link to comment https://forums.phpfreaks.com/topic/212652-how-to-display-an-image-in-a-popup-window/#findComment-1107893 Share on other sites More sharing options...
laanes Posted September 6, 2010 Author Share Posted September 6, 2010 Just a comment really for future reference - as of php4.1.0 $HTTP_GET_VARS, $HTTP_POST_VARS and $HTTP_POST_FILES was/is deprecated. The preferred method of accessing these global values is like so:- $_POST: http://www.php.net/manual/en/reserved.variables.post.php $_GET: http://www.php.net/manual/en/reserved.variables.get.php $_FILES: http://www.php.net/manual/en/reserved.variables.files.php Not forgetting that this array ($_FILES) has five or six different parameters to it too, very helpful they are:- (Shamelessly pinched from the php.net website...) [name] => MyFile.jpg [type] => image/jpeg [tmp_name] => /tmp/php/php6hst32 [error] => UPLOAD_ERR_OK => 98174 Just thought I should highlight this point as I am seeing this becoming more and more popular as a coding error (fails when people upgrade to V5) Cheers, Rw Changed those variable names around as you recommended, might be useful, you never know. Quote Link to comment https://forums.phpfreaks.com/topic/212652-how-to-display-an-image-in-a-popup-window/#findComment-1108042 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.