Jump to content

[SOLVED] images aren't rendering


march

Recommended Posts

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

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.

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.

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.

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.