Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
391 views
in Technique[技术] by (71.8m points)

php - Upload doesn't work right when the file is too big

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

56.7k users

...