我想允许将非常大的文件上传到我们的PHP应用程序中(数百个megs - 8演出).然而,这有几个问题.
浏览器:
服务器:
要求:
我很惊讶在我的错误日志中找到上述错误,因为我认为我已经完成了必要的工作以捕获我的PHP脚本中的错误:
if ($_FILES['image']['error'] == 0)
{
// go ahead to process the image file
}
else
{
// determine the error
switch($_FILES['image']['error'])
{
case "1":
$msg = "Uploaded file exceeds the upload_max_filesize directive in php.ini.";
break;
....
}
}
Run Code Online (Sandbox Code Playgroud)
在我的PHP.ini脚本中,相关设置是:
memory_limit = 128M
post_max_size = 3M
upload_max_filesize = 500K
Run Code Online (Sandbox Code Playgroud)
据我所知,3M相当于3145728字节,这就是触发错误的原因.如果文件大小超过500K但小于3m,PHP脚本将能够按照正常运行,在发出错误信息$msg
按case 1
.
当帖子大小超过post_max_size
但仍然在内存限制范围内时,如何捕获此错误而不是让脚本突然终止并发出PHP警告?我在这里,这里和这里看过类似的问题,但找不到答案.
今天我正在为头像制作文件上传,一切都很好,它调整图像大小等,但偶尔选择一个大而无效的文件时会产生这个错误:
Warning: POST Content-Length of 52091839 bytes exceeds the limit of 8388608 bytes in Unknown on line 0
You did not select a file to upload.
Run Code Online (Sandbox Code Playgroud)
这种情况并不是偶尔发生的.通常它只是在文件太大时给出正确的错误消息.
有没有人知道这个错误来自哪里,为什么它显示?
谢谢!