getimagesize() - Works on one server and not another

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
joadard
Forum Newbie
Posts: 5
Joined: Thu Oct 26, 2006 6:38 am

getimagesize() - Works on one server and not another

Post 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?
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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;" />'; 
}
joadard
Forum Newbie
Posts: 5
Joined: Thu Oct 26, 2006 6:38 am

Post 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.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

joadard wrote:I was having difficulties with the above code
please elaborate.
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

echo '$image' to make sure that the folder / file is indeed what you think it is.
joadard
Forum Newbie
Posts: 5
Joined: Thu Oct 26, 2006 6:38 am

Post 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!
Post Reply