Jump to content

[SOLVED] GetImageSize cant find the image?


mike12255

Recommended Posts

Im getting the following error on a page:

 

Warning: getimagesize(/images/product029.jpg) [function.getimagesize]: failed to open stream: No such file or directory in /home/schoolw1/public_html/showproduct.php on line 111

 

the url is: http://schoolworkanswers.com/showproduct.php?id=86 and if you add /images/product029.jpg after the schoolworkanswers.com/ it brings you to the picture so i dont know why its not working ill post my code below and i'd appriciate if somone could tell me what im doing wrong.

 

<?php
	//take the .. off the first slash in the path
			$path = str_replace("..","",$pd_path);
			//set the width and hight to vars
			list($w, $h) = getimagesize($path);
			//is the width bigger then our table?
			if ($w < 660){
	echo "<td align=center><img src=$pd_path width= height= alt=><td>";
	}else{
	//this one resizes the width of the pic so the table dosnt expand.
echo "<td align=center><img src=$pd_path width=650 alt=><td>";		

	}



?>

Link to comment
https://forums.phpfreaks.com/topic/155270-solved-getimagesize-cant-find-the-image/
Share on other sites

A leading slash / on a URL refers to the domain root. A leading slash on a file system path (which is what getimagesize()) is being given, refers to the root of the current hard disk. You need to give the getimagesize() function a path to where the file is at on the disk. Use either a relative path to the image from where the script is at or an absolute path on the disk.

Place a period "." in front of the first slash, making the path: "./images/product029.jpg" or simply remove the first slash and period.  The reason is because the / refers to the root of the directory structure.  The period is a reference to "this folder" similar to the way that the double periods refer to "parent folder."  In other words, if you are currently in path: /var/www/display.php and you say: require("/content.php"); you will try to load the file /content.php, though surely what you want is to load /var/www/content.php.

 

Sort of difficult to explain, and I'm trying to get back to you within your time frame.

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.