Page 1 of 1

Uploading images with php (Not that simple)

Posted: Mon May 24, 2004 2:27 pm
by mikebr
I have written some code to upload images on my web site, after testing it with various images I find that it sometimes returns empty values, for example the following code used with . JPG images taken on my Nicon coolpix returns the $file_name, $file_type and $file_temp_name values as being empty and the $file_size returns 0. Other images are not a problem, I even tried running the problem images through Photoshop as jpg and gif but it makes no difference, the image information is not read from these images although Photoshop can read the file size fine.

The code I am using as far as I know is the normal code used with php to read these values which is below:

Can anyone shine any light on what this problem might be?

Code: Select all

<?php
	$file_name = $_FILES['uploadfile']['name'];
	$file_temp_name = $_FILES['uploadfile']['tmp_name'];
	$file_size = $_FILES['uploadfile']['size'];
	$file_type = $_FILES['uploadfile']['type'];
	$file_name = trim($file_name);
	
	echo "file_name=$file_name<br />file_size=$file_size<br />file_type=$file_type";
	exit
?>

Posted: Mon May 24, 2004 2:51 pm
by phice
Can you manually upload an example image for us?

Posted: Mon May 24, 2004 3:16 pm
by mikebr
I have placed an image at:

http://REMOVED.com/DSCN2463.JPG

I take it this is what you mean?

Thanks

Posted: Mon May 24, 2004 3:20 pm
by markl999
Weird, if you view the image properties, it's alternative text is:
The image “http://onlinepropertylist.com/DSCN2463.JPG” cannot be displayed, because it contains errors.

Posted: Mon May 24, 2004 3:27 pm
by feyd
I get:
Type: JPEG Image
Size: 72295 bytes
Dimensions: 640 x 480 pixels
Created today.

Posted: Mon May 24, 2004 4:03 pm
by mikebr
I did a print_r($_FILES); on the image and get the following:
Array ( [uploadfile] => Array ( [name] => DSCN2463.jpg [type] => [tmp_name] => [error] => 2 [size] => 0 ) ) file_name=DSCN2463.jpg
The image is 72 KB so it can't be too large.

Thanks

Posted: Mon May 24, 2004 4:36 pm
by markl999
Strange. Error 2 is UPLOAD_ERR_FORM_SIZE
"The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form."

What does the form look like?

Posted: Mon May 24, 2004 4:57 pm
by mikebr
Thats it...

OK, It didn't enter my brain that the filesize error related to the permitted file size set in the actual form. I set this size using a "config file" variable and check it against the same in the actual upload script, I had it set at 30000 when it should have been 300000 so the file was in fact too large for my permitted file size.

Thanks for the replies.