views:

35

answers:

3

I have a PHP app where I can upload files. When I upload most files and do a print_r($_FILES), I get something like this:

Array
(
    [import] => Array
        (
            [name] => Array
                (
                    [excel_file] => COD MKTG 2.csv
                )

            [type] => Array
                (
                    [excel_file] => application/vnd.ms-excel
                )

            [tmp_name] => Array
                (
                    [excel_file] => /tmp/phpy8mEKn
                )

            [error] => Array
                (
                    [excel_file] => 0
                )

            [size] => Array
                (
                    [excel_file] => 1584286
                )

        )

)

I have another CSV file that's more like 13 megabytes, and when I try to upload that, I get this:

Array
(
    [import] => Array
        (
            [name] => Array
                (
                    [excel_file] => COD MKTG.csv
                )

            [type] => Array
                (
                    [excel_file] => 
                )

            [tmp_name] => Array
                (
                    [excel_file] => 
                )

            [error] => Array
                (
                    [excel_file] => 1
                )

            [size] => Array
                (
                    [excel_file] => 0
                )

        )

)

I don't get any error saying the file's too big. I just get a malformed $_FILES. I have post_max_size in php.ini set to 100MB. Why is this happening?

+1  A: 

change the memory limit aswell memory_limit = 8M ;

to perhaps 20?

and perhaps execution time

max_execution_time

edit:

make sure its not execution time look it up...

if you got a really slow internet connection it could be

max_input_time

it has to be one of these or there's something wrong with your script or your not setting the settings correctly

memory_limit

max_execution_time

max_input_time

Breezer
No, my memory_limit was 128M and I still get the same results at 256. My script's not timing out, either.
Jason Swett
updated the answer
Breezer
+3  A: 

As per the PHP docs, error code 1 is UPLOAD_ERR_INI_SIZE: "The uploaded file exceeds the upload_max_filesize directive in php.ini"

You need to make sure all the following variables are properly set:

upload_max_filesize - max size of any individual file in an upload
max_file_uploads - total number of files allowed to be uploaded
post_max_size - sum total of all data being POSTed (form data + files)
memory_limit - must be > post_max_size, to allow space for PHP + script overhead

And on top of that, there's the web server limits as well. Apache's got LimitRequestBody which would apply long before PHP ever enters the picture.

Marc B
+1 for webserver LimitRequestBody reference
Mark Baker
It turned out to be `upload_max_filesize`. I could tell because the error code was "1": http://php.net/manual/en/features.file-upload.errors.php
Jason Swett
Yep. that was in your original post.
Marc B
A: 

You could also try setting these values in a .htaccess file within your root directory

php_value upload_max_filesize 128M
php_value post_max_size 128M
php_value max_execution_time 200
php_value max_input_time 200
Brad