Uploading images with php (Not that simple)

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
mikebr
Forum Contributor
Posts: 243
Joined: Sat Sep 28, 2002 7:05 am

Uploading images with php (Not that simple)

Post 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
?>
User avatar
phice
Moderator
Posts: 1416
Joined: Sat Apr 20, 2002 3:14 pm
Location: Dallas, TX
Contact:

Post by phice »

Can you manually upload an example image for us?
Image Image
mikebr
Forum Contributor
Posts: 243
Joined: Sat Sep 28, 2002 7:05 am

Post by mikebr »

I have placed an image at:

http://REMOVED.com/DSCN2463.JPG

I take it this is what you mean?

Thanks
Last edited by mikebr on Wed Feb 01, 2006 2:11 pm, edited 1 time in total.
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

I get:
Type: JPEG Image
Size: 72295 bytes
Dimensions: 640 x 480 pixels
Created today.
mikebr
Forum Contributor
Posts: 243
Joined: Sat Sep 28, 2002 7:05 am

Post 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
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post 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?
mikebr
Forum Contributor
Posts: 243
Joined: Sat Sep 28, 2002 7:05 am

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