問(wèn)題描述
我有一個(gè) PHP 應(yīng)用程序,我可以在其中上傳文件.當(dāng)我上傳大多數(shù)文件并執(zhí)行 print_r($_FILES)
時(shí),我得到如下信息:
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
)
)
)
我有另一個(gè) 13 兆字節(jié)的 CSV 文件,當(dāng)我嘗試上傳它時(shí),我得到了這個(gè):
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
)
)
)
我沒(méi)有收到任何說(shuō)文件太大的錯(cuò)誤.我只是得到一個(gè)格式錯(cuò)誤的 $_FILES
.我將 php.ini 中的 post_max_size
設(shè)置為 100MB.為什么會(huì)發(fā)生這種情況?
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?
推薦答案
根據(jù) PHP 文檔,錯(cuò)誤代碼 1 是 UPLOAD_ERR_INI_SIZE: "上傳的文件超過(guò)了 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"
您需要確保正確設(shè)置以下所有變量:
You need to make sure all the following variables are properly set:
upload_max_filesize - 任何文件的最大大小上傳中的單個(gè)文件
max_file_uploads - 允許的文件總數(shù)上傳
post_max_size - 發(fā)布的所有數(shù)據(jù)的總和(表單數(shù)據(jù)+文件)
memory_limit - 必須 > post_max_size,以便為PHP + 腳本開(kāi)銷
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
除此之外,還有網(wǎng)絡(luò)服務(wù)器限制.Apache 的 LimitRequestBody 早在 PHP 出現(xiàn)之前就適用了.
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.
這篇關(guān)于文件太大時(shí)上傳不正確的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!