I'm trying to build a crude album viewing site. There are three files I'm working with:

  • index.php: Contains html code.
  • images.php: Builds images from browser URL and an array.
  • include: Builds an array of images from a given directory.


	$image = $_GET['show_img'];
	$tmp_img = $my_pics[$image];

	//@imagecopyresized( $tmp_img, $img, 0, 0, 100, 100, $new_width+100, $new_height+100, $width, $height );
	header('Content-Type: image/jpeg');

	@imagejpeg( $tmp_img );	

All I get for output is the address I put in to begin with. I have gotten this type of setup to work before, just not with the way I want to include the array setup.

function buildImageArray($pathToImages)
	$dir = opendir( $pathToImages );
	$counter = 0;
	while (false !== ($fname = readdir( $dir ))) {
		$info = pathinfo($pathToImages . $fname);
		if ( strtolower($info['extension']) == 'jpg' )
			$img = imagecreatefromjpeg( "{$pathToImages}{$fname}" );
			$width = imagesx( $img );
			$height = imagesy( $img );
			$tmp_img = imagecreatetruecolor( $width, $height );
			$image_container[$counter] = $tmp_img;
	closedir( $dir );

/*function fillImageArrays($container)
	// fill large ones

My index.php file has something simple like:

<img src="images.php?show_img=3" />

However, sometimes when I load the page I get nothing, but other times I refresh the page quickly and can see a broken image.

I have all of the error reporting turned on, but I'm not getting any errors at all.

I have had some very basic PHP experience in the past, but I code very well in C++. Can anyone point me in the write direction, or point out a syntax error I am overlooking?

9 Years
Discussion Span
Last Post by cwarn23
@imagejpeg( $tmp_img );

Line 11 in the above quote is incorrect. You first need to get the image then use a separate function to display the image. To make it simple, I have combined them into one line so try replacing line 11 in the above quote with the following


Also you may want to check the following link for more info:

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.