問題描述
我有一個 PHP 應用程序,我可以在其中上傳文件.當我上傳大多數文件并執行 print_r($_FILES)
時,我得到如下信息:
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
)
)
)
我有另一個 13 兆字節的 CSV 文件,當我嘗試上傳它時,我得到了這個:
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
)
)
)
我沒有收到任何說文件太大的錯誤.我只是得到一個格式錯誤的 $_FILES
.我將 php.ini 中的 post_max_size
設置為 100MB.為什么會發生這種情況?
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?
推薦答案
根據 PHP 文檔,錯誤代碼 1 是 UPLOAD_ERR_INI_SIZE: "上傳的文件超過了 php.ini 中的 upload_max_filesize 指令"
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_file_uploads - 允許的文件總數上傳
post_max_size - 發布的所有數據的總和(表單數據+文件)
memory_limit - 必須 > post_max_size,以便為PHP + 腳本開銷
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
除此之外,還有網絡服務器限制.Apache 的 LimitRequestBody 早在 PHP 出現之前就適用了.
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.
這篇關于文件太大時上傳不正確的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!