views:

80

answers:

2

Hello,

I'm trying to debug a very strange problem with the $_FILES array. When I try to upload a file, only the 'name' key is set, the type, tmp_name, etc. are empty, and it's returning error #1. For example:

Array
(
    [name] => test.doc
    [type] => 
    [tmp_name] => 
    [error] => 1
    [size] => 0
)

test.doc is a valid file, I can open it without a problem. This is happening to a bunch of files I tested; doc, pdf, xls, ppt, jpg. The only file types that works are txt and gif.

I'm getting this problem on both on CentOS 5.3 w/PHP 5.2.6, Apache 2.2.3 and Ubuntu 8.04 w/PHP 5.2.4, Apache 2.2.8.

I thought I may have been mime types, but I checked the mime types and all the common ones are available.

Any ideas? I've never had this problem before!

Thanks.

+7  A: 

The error code of 1 means the file exceeds the maximum upload size set in php.ini.

All the various errors messages are explained here: http://php.net/manual/en/features.file-upload.errors.php

Tim Cooper
Would upvote if I could - out of votes for today.
Pekka
+4  A: 

According to the PHP documentation on file uploads, an error value of 1 (AKA UPLOAD_ERR_INI_SIZE) means:

The uploaded file exceeds the upload_max_filesize directive in php.ini.

You can try adjusting the upload-max-filesize setting.

EDIT: The correct syntax for specifying upload_max_filesize in megabytes is 25M, not 25MB. See the documentation on using shorthand for details.

Asaph
This is it. Would upvote if I could.
Pekka
Hehe, Pekka, did you already vote 35 times today?
Asaph
Obviously - I've run out of votes! Is 35 the number?
Pekka
Sorry, I didn't mention that the files I'm trying to upload are very small <100KB. I have upload_max_filesize set to 25MB and post_max_size to 100MB
Daniel
Actually, looks like the daily vote cap is 30, not 35 like I initially stated. See here: http://meta.stackoverflow.com/questions/5212/are-there-any-voting-limits-in-stackoverflow
Asaph
@Daniel: Perhaps the values in your `php.ini` are being overridden by either your Apache vhost config or at runtime. What is the output of `echo "upload_max_filesize = " . ini_get('upload_max_filesize');` when executed in your file upload handling script?
Asaph
Asaph, I get 25MB. For testing, I have a simple form with input type of file and submit button. In PHP, I'm just printing out the $_FILES array for the file input field, `print_r($_FILES['file_upload']);`
Daniel
@Daniel: The syntax of "25MB" looks slightly wrong. Try changing it to "25M" in `php.ini`. See the following link for shorthand syntax: http://www.php.net/manual/en/faq.using.php#faq.using.shorthandbytes
Asaph
@Asaph, Oh man, that did it! I was totally blinded by it, `post_max_size` was properly set to 100M, but the value for `upload_max_filesize` was 25MB. Thanks so much!
Daniel
@Daniel: You're most welcome. I'm glad we got to the bottom of that. :) Wouldn't it be nice if php would simply barf on a syntax error in `php.ini` instead of silently using a default value?
Asaph
@Asaph, Yep, it would have been nice to get a notice for syntax error with `php.ini` settings :P
Daniel