[英]How to avoid: Warning: POST Content-Length of 47820076 bytes exceeds the limit of 8388608 bytes in Unknown on line 0
I am posting an image file to the server and everything is fine. 我正在向服务器发布一个图像文件,一切都很好。 However, in cases when the user posts something bigger I get this warning.
但是,如果用户发布更大的内容,我会收到此警告。 What could I do to avoid this warning?
我该怎么做才能避免这种警告?
I don't want solutions that would hide the warning nor increase the post size. 我不想要隐藏警告的解决方案,也不希望增加邮政大小。 I want something that would block the request from uploading the file to the server entirely and catch that warning.
我想要一些阻止请求完全将文件上传到服务器并捕获该警告的内容。
This is what worked for me. 这对我有用。 It seems that when PHP sees a file that is too large, deletes all the POST data.
似乎当PHP看到文件太大时,删除所有POST数据。 So this code fragment worked for me:
所以这段代码片段对我有用:
if ($_SERVER['REQUEST_METHOD'] == 'POST' && count($_POST) < 1 ) {
$_SESSION['error'] = 'File upload size exceeded';
header('Location: index.php');
return;
}
Of course your page should be designed not to submit empty POST pages with no input parameters. 当然,您的页面应设计为不提交没有输入参数的空POST页面。
One thing what you can do is give a maximum size on the HTML form. 您可以做的一件事是在HTML表单上给出最大大小。
<input type="hidden" name="MAX_FILE_SIZE" value="4194304" />
It's not bulletproof, but it has some impact. 它不是防弹的,但它有一些影响。 Why this is not so good is explained in this comment - it is only checked by PHP, so uploading will start and continue up until this limit is reached.
为什么这不是那么好在本评论中解释 - 它仅由PHP检查,因此上传将开始并继续,直到达到此限制。
My recommendation is that you could use that together with a javascript solution, as described here . 我的建议是,你可以一起使用了JavaScript的解决方案,如所描述这里 。 It only works if javascript is enabled, of course.
它只适用于启用javascript的情况。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.