Jump to content

Image Display Issue


dandelo

Recommended Posts

I searched the forums, as well as browsed through the most recent ten pages, but I couldn't find anything that seemed to help.

 

What I'm trying to accomplish is that I want a php script that will do nothing but display an image.  The reason for this is that I'm making a photography gallery for myself, and I want to have one script that will handle all my photos.  Here is what I've done thusfar:

 

In one iFrame, I have a list of thumbnails which link to my display.php file in the following method:

 

<a href="display.php?pid=school_chalk_1">

 

Then, within my php file is the following code:

 

<?php
print "<img src='../photos/" . $pid . ".jpg'>";
?>

 

However, when I click on the link, all I get is a blank page.  Is there something obviously wrong?? I've tried several variations on this, but nothing has worked.  I have found that it works if I include the name of the file in the php code instead of using the variable, but as soon as I put the variable back in, it no longer works.

 

I'm relatively inexperienced with php as all that I have ever used it for was includes and so forth..  Any help?

 

- Brad

Link to comment
Share on other sites

By linked to the right page, are you referring to the link in the thumbnails panel that links to the php script, or the line of code in the php file that links to the image?

 

The link in the thumbnails panel has a target of self, since that's how it was when I uploaded it (I'm now using my host's code editor to try things out) and that page goes blank when I click on the thumbnail.  So I think that's linked correctly..

 

I'm also pretty sure that the image is linked properly (a correct relative path), since if I replace the variable with the file name, it works.

 

- Brad

Link to comment
Share on other sites

Your problem is that you're relying on register_globals which probably isn't enabled.  You can try this in display.php:

 

<?php
$pid = trim(urldecode($_GET['pid']));
if (isset($pid) && !empty($pid) && file_exists('../photos/' . $pid . '.jpg'))
{
     print "<img src='../photos/" . $pid . ".jpg' />";
}
else
{
     print "Image does not exist";
}
?>

Link to comment
Share on other sites

@ Bauer418 - You're a savior, haha, thank you VERY much.  I don't think I could properly express my gratitude.  Now I need to figure out how it works, since I consider C&P a lame way to code anything (I've been programming VB6 for years and I refuse to C&P, lol).  But yes, thank you very much!

 

And to the others who took the time to post, thank you too!  :D

 

- Brad

Link to comment
Share on other sites

register_globals is an old way in which global variables (url parameters, posted data, cookies, sessions, etc.) would be assigned to a variable with their name.  For example, consider the url:

 

index.php?test=true

 

In the index.php script, $test would automatically be set to the value true.  Eventually, PHP realized what kind of a security flaw this was.  If your site relied on a variable $logged_in to determine if a user was logged in, in theory, someone could come to your site with the url

 

index.php?logged_in=1

 

And PHP would replace whatever previously defined variable of $logged_in you had, with the value 1 set from the URL.  So, register_globals was removed, and now you're forced to use $_GET for parameters in the URL, $_POST for posted data, $_COOKIE for cookies, $_SESSION for sessions, etc.

 

That basically sums up the first line of the code (with the exception of knowing that urldecode and trim are just to clean up the value).

 

The rest of the code checks to see if the image exists (the purpose of the if statement) and then displays it if it does.  If not, it displays the alternative text.

Link to comment
Share on other sites

Thank you yet again.. that saves me a good deal of time, and I am very grateful.

 

I used to use register_global variables to make my includes work, but it's been a long time since I've done a site that way, and I guess things have changed.  Oh well, at least there are people that can help. :)

 

- Brad

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.