getimagesize returning nothing

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
SidewinderX
Forum Contributor
Posts: 407
Joined: Fri Jul 16, 2004 9:04 pm
Location: NY

getimagesize returning nothing

Post by SidewinderX »

I have a function called checkUpload() which is suppose to check the attributes a file to be uploaded. If it passes all the checks, the file is uploaded. The only types of files to be uploaded are images [which will be filtered later], but I'm trying to get the image x and image y [without using GD].

Here is my code:

Code: Select all

$uploaddir = "/var/www/upload/";
	$uploadfile = $uploaddir . basename($_FILES['uploadedfile']['name']);
	$path_parts = pathinfo($uploadfile);

	/********DEBUG INFO********/
	echo "Max Image Width: $tl_maxwidth<br />";
	echo "Max Image Height: $tl_maxheight<br />";
	echo "Upload Directory: $uploaddir<br />";
	echo "Upload Directory exists: " . is_dir($uploaddir) . "<br />";
	echo "Upload Directory is writable: " . is_writable($uploaddir) . "<br />";
	echo "Upload Properties: " . print_r($_FILES) . "<br />";
	echo "Max Upload size is: " . ini_get('post_max_size') . "<br />";
	$size = getimagesize($uploadfile);
	echo "Image Width: " . $size[0] . "<br />";
	echo "Image Height: " . $size[1] . "<br />";
	/**************************/
And this is what is returned:
Max Image Width: 400
Max Image Height: 60
Upload Directory: /var/www/upload/
Upload Directory exists: 1
Upload Directory is writable: 1
Array ( [uploadedfile] => Array ( [name] => banner1.png [type] => image/png [tmp_name] => /tmp/phpLgol7D [error] => 0 [size] => 46580 ) ) Upload Properties: 1
Max Upload size is: 8M
Image Width:
Image Height:
The size is not being returned. I've tried this for 2 PNG images and 1 JPG image, and none of them worked. However, I tried this for a GIF image and it worked.
Max Image Width: 400
Max Image Height: 60
Upload Directory: /var/www/upload/
Upload Directory exists: 1
Upload Directory is writable: 1
Array ( [uploadedfile] => Array ( [name] => 88x31_2.GIF [type] => image/gif [tmp_name] => /tmp/php117DHw [error] => 0 [size] => 3441 ) ) Upload Properties: 1
Max Upload size is: 8M
Image Width: 88
Image Height: 31
I'm not really sure what's wrong. Can anyone shed some light on this?

Thanks.
miro_igov
Forum Contributor
Posts: 485
Joined: Fri Mar 31, 2006 5:06 am
Location: Bulgaria

Post by miro_igov »

I believe you should use

Code: Select all

$size = getimagesize($_FILES['uploadedfile']['tmp_name']);
Because it includes the path and filename of the temporary uploaded file, while $_FILES['uploadedfile']['name'] contains only the name of the file, but this file does not yet exist on your system because you did not yet used move_uploaded_file();
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

Yes, you have to get the size of the temp file, because $uploadfile doesn't exist until you move it to that path. The fact that the gif works, means that your check is allowing the gif to be moved.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
SidewinderX
Forum Contributor
Posts: 407
Joined: Fri Jul 16, 2004 9:04 pm
Location: NY

Post by SidewinderX »

works perfect, thanks guys
Post Reply