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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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