Page 1 of 1

getimagesize() - Works on one server and not another

Posted: Thu Oct 26, 2006 6:44 am
by joadard
Hi,

I have code to generate thumbnail images that I have used in several sites and it works well... except that I tried loading it on a new server for a new site and it doesn't work properly. Here is the code:

Code: Select all

$image = ($_SERVER["DOCUMENT_ROOT"]."/".$photoRow['PicName']);                
										
						 $size = getimagesize("$image");
						 $type = $size['mime'];
						 $height = $size[1];
						 $width = $size[0];
						
								
							 if ($height > 150)
								 {
									   $height = 150;
									   $percent = ($size[1] / $height);
									   $width = ($size[0] / $percent);
								 }
							 else if ($width > 150)
								 {
									   $width = 150;
									   $percent = ($size[0] / $width);
									   $height = ($size[1] / $percent);
								 }
							 
     				
		echo "<img src='/images/propertyimages/".stripslashes($photoRow['PicName'])."' border='0' style='width: ".$width."px; height: ".$height."px;'><p>";
Here is what I get:

<img src='/images/propertyimages/picname.jpg' border='0' style='width: px; height: px;'>

The path is correct and the filename is correct, but nothing appears on the page - it looks as though the file is not found. Clearly its not measuring the height or width. I have the errors turned on and nothing is generated. I'm lost!

Anyone have any suggestions?

Posted: Thu Oct 26, 2006 7:46 am
by volka
getimagesize("$image")
no need for quotes here.
stripslashes($photoRow['PicName'])
stripslashes? Why?

please try

Code: Select all

error_reporting(E_ALL);
ini_set('display_errors', true);

$image = ($_SERVER["DOCUMENT_ROOT"]."/".$photoRow['PicName']);
if ( !file_exists($image) ) {
	echo '<p>no such file: "', $image, '"</p>';
}
else if ( false===($size=getimagesize($image)) ) {
	echo '<p>cannot determine type of file: "', $image, '"</p>';
}
else {
	$type = $size['mime'];
	$height = $size[1];
	$width = $size[0];
	
	if ($height > 150) {
		$height = 150;
		$percent = ($size[1] / $height);
		$width = ($size[0] / $percent);
	}
	else if ($width > 150) {
		$width = 150;
		$percent = ($size[0] / $width);
		$height = ($size[1] / $percent);
	}
	echo '<img src="/images/propertyimages/', stripslashes($photoRow['PicName']), '" border="0" style="width:', $width, '"px; height:', $height, 'px;" />'; 
}

Posted: Thu Oct 26, 2006 12:27 pm
by joadard
I was having difficulties with the above code, but did make one or two changes to mine and got a little further ahead:

Code: Select all

$image = $_SERVER["DOCUMENT_ROOT"]."/images/propertyimages/".$photoRow['PicName'];                
						 $size = getimagesize($image);
						   $height = $size[1];
						   $width = $size[0];
							 if ($height > 150)
								 {
									   $height = 150;
									   $percent = ($size[1] / $height);
									   $width = ($size[0] / $percent);
								 }
							 else if ($width > 150)
								 {
									   $width = 150;
									   $percent = ($size[0] / $width);
									   $height = ($size[1] / $percent);
								 }
							 
     				
		echo "<img src='/images/propertyimages/".stripslashes($photoRow['PicName'])."' border='0' height=\"$height\" width=\"$width\"><p>";
Now I am getting the following error:

failed to open stream: No such file or directory...

??

The file is there - I have checked.

Posted: Thu Oct 26, 2006 1:01 pm
by volka
joadard wrote:I was having difficulties with the above code
please elaborate.

Posted: Thu Oct 26, 2006 1:15 pm
by Burrito
echo '$image' to make sure that the folder / file is indeed what you think it is.

Posted: Thu Oct 26, 2006 1:50 pm
by joadard
doh!

I had already done that but hadn't noticed that there was a directory mixup there.

I also had to remove a slash in front of /images to make it work and now it works like a charm.

Thanks to all!