Jump to content

How to display an image in a popup window?


laanes

Recommended Posts

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

 

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

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. 

Link to comment
Share on other sites

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.

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.