当文件太大时上传不起作用 [英] Upload doesn't work right when the file is too big
问题描述
我有一个PHP应用程序,可以上传文件。当我上传大多数文件并执行 print_r($ _ FILES)
时,我得到如下所示:
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
)
)
)
我有另一个CSV文件,我更喜欢13兆字节,当我尝试上传时,我得到这个:
$ b $ pre $ $ $ $ c $ Array
(
[import] =>数组
(
[name] =>数组
(
[excel_file] => COD MKTG.csv
)
[数组
(
[excel_file] =>
)
[tmp_name] =>数组
(
[excel_file] =>
)
[error] => Array
(
[excel_file] => 1
)
[size] => Array
(
[excel_file] => 0
)
)
)
我不会收到任何错误,说文件太大。我只是得到一个格式不正确 $ _ FILES
。我在php.ini中将 post_max_size
设置为100MB。为什么会发生这种情况?
根据PHP文档,错误代码1是 UPLOAD_ERR_INI_SIZE :上传的文件超过了php.ini文件中的upload_max_filesize指令。
您需要确保以下所有变量设置正确:
upload_max_filesize - 上传任何单个文件的最大大小
max_file_uploads - 允许上传的文件总数
post_max_size - 所有数据的总和被张贴(表单数据+文件)
memory_limit - mu st> post_max_size,为PHP +脚本开销留出空间
最重要的是,还有web服务器的限制。 Apache的 LimitRequestBody 在PHP进入图片之前很久就会使用。
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?
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.
这篇关于当文件太大时上传不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!