dandelo Posted February 23, 2008 Share Posted February 23, 2008 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 Quote Link to comment Share on other sites More sharing options...
Chris92 Posted February 23, 2008 Share Posted February 23, 2008 Are you sure it's linked to the right page? Quote Link to comment Share on other sites More sharing options...
dandelo Posted February 23, 2008 Author Share Posted February 23, 2008 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 Quote Link to comment Share on other sites More sharing options...
metalhead41 Posted February 23, 2008 Share Posted February 23, 2008 when you are looking at the blank page view the source, what is there for the image (if anything)? Quote Link to comment Share on other sites More sharing options...
Bauer418 Posted February 23, 2008 Share Posted February 23, 2008 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"; } ?> Quote Link to comment Share on other sites More sharing options...
dandelo Posted February 23, 2008 Author Share Posted February 23, 2008 @ 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! - Brad Quote Link to comment Share on other sites More sharing options...
Bauer418 Posted February 23, 2008 Share Posted February 23, 2008 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. Quote Link to comment Share on other sites More sharing options...
dandelo Posted February 23, 2008 Author Share Posted February 23, 2008 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 Quote Link to comment 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.