Page 1 of 1

getimagesize returning nothing

Posted: Fri Aug 03, 2007 12:33 pm
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.

Posted: Fri Aug 03, 2007 12:41 pm
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();

Posted: Fri Aug 03, 2007 2:28 pm
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.

Posted: Fri Aug 03, 2007 4:35 pm
by SidewinderX
works perfect, thanks guys