march Posted October 22, 2009 Share Posted October 22, 2009 I'm trying to call a JPG file from within PHP (in an effort to hide the actual JPG folder). The image is supposed to be called at domain.com/photo/?id=X&i=Y where X is the gallery ID and Y is the image number, but it doesn't seem to be working. I've done this before but copying and pasting the code doesn't seem to be working. What am I missing? if (isset($_GET['id']) && isset($_GET['i'])) { //get folder location of photos $gallery_path = mhp_get_gallery_filepath($_GET['id']).'/'; //return filenames of all jpgs in folder $imgs = (mhp_img_list($gallery_path)); //get name of i-th jpg file $img = $imgs[(int) $_GET['i']]; //check to see if the image exists if (file_exists($gallery_path.$img) && is_readable($gallery_path.$img) && getimagesize($gallery_path.$img)) { header('Content-Type: image/jpeg'); $orgimage = imagecreatefromjpeg($gallery_path.$img); imagejpeg($orgimage, NULL, 90); imagedestroy($origimage); } } Link to comment https://forums.phpfreaks.com/topic/178640-solved-images-arent-rendering/ Share on other sites More sharing options...
mrMarcus Posted October 22, 2009 Share Posted October 22, 2009 what is happening/where is the script breaking? Link to comment https://forums.phpfreaks.com/topic/178640-solved-images-arent-rendering/#findComment-942261 Share on other sites More sharing options...
march Posted October 22, 2009 Author Share Posted October 22, 2009 what is happening/where is the script breaking? Nothing is happening, I get a blank page with the URL as the page's text. I've managed to figure out that it's working and it's inside the if statement that displays the image but it just isn't displaying. I can't seem to find an error log to see if the code is calling any errors. Link to comment https://forums.phpfreaks.com/topic/178640-solved-images-arent-rendering/#findComment-942269 Share on other sites More sharing options...
lemmin Posted October 22, 2009 Share Posted October 22, 2009 Your file location is probably not what you expect. Try echoing out the $gallery_path.$img and see if there is actually something there. Link to comment https://forums.phpfreaks.com/topic/178640-solved-images-arent-rendering/#findComment-942302 Share on other sites More sharing options...
march Posted October 22, 2009 Author Share Posted October 22, 2009 Your file location is probably not what you expect. Try echoing out the $gallery_path.$img and see if there is actually something there. if that's the case, shouldn't the last if statement catch it? it would only try to export something if the file exists, is readable and an image. Here are the variable values when I try to create the image: $gallery_path = /home/username/domain.com/photos/gallery/concerts/band-09-10-15/ $img = DSC_7108.jpg The image is there because when I remove the '/home/username/' from the path string I can call up the original photo from my webbrowser. I'm just confused to why it can find the file but can't display it. Link to comment https://forums.phpfreaks.com/topic/178640-solved-images-arent-rendering/#findComment-942317 Share on other sites More sharing options...
march Posted October 23, 2009 Author Share Posted October 23, 2009 would having a link to the non-working image help? http://www.marchodgesphotography.com/wp/photo/?id=22&i=1 Link to comment https://forums.phpfreaks.com/topic/178640-solved-images-arent-rendering/#findComment-942557 Share on other sites More sharing options...
lemmin Posted October 23, 2009 Share Posted October 23, 2009 if that's the case, shouldn't the last if statement catch it? Exactly. The if statement would not execute and nothing would show up on the page. That is what you are saying is happening, right? I still think something is wrong with the file path. Try using the real image: echo '<img src="'.$gallery_path.$img.'" />'; If that can't be displayed, then the path is wrong. Link to comment https://forums.phpfreaks.com/topic/178640-solved-images-arent-rendering/#findComment-943110 Share on other sites More sharing options...
march Posted October 31, 2009 Author Share Posted October 31, 2009 ok, I finally figured it out. The problem was that I had two separate PHP sections. <?php /* template comments */ ?> <?php /* code went here */ ?> It was the gap between two PHP sections that that caused the error. Once I turned the two PHP sections into one section then it worked. Thanks for the help guys. Link to comment https://forums.phpfreaks.com/topic/178640-solved-images-arent-rendering/#findComment-948359 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.