php上传文件超过post_max_size时如何显示错误?
当上传的文件超过 post_max_size
php 时如何显示错误?
print_r($_FILES);
当我超过 post_max_size
时,我得到一个空数组
array()
,我从 php.net 得到这个,但我不理解它,也不知道该怎么做,
如果post数据的大小大于post_max_size,$_POST和 $_FILES 超全局变量为空。这可以通过多种方式进行跟踪, 例如,通过将 $_GET 变量传递给处理数据的脚本, 即,然后检查是否 $_GET['processed'] 已设置。
这是我的表格,
<form action="upload.php" method="post" enctype="multipart/form-data">
<input type="file" multiple="multiple" name="file[]" />
<input type="submit" name="upload" value="Submit"/>
</form>
How to display an error when the uploaded files are exceeding post_max_size
php?
print_r($_FILES);
I get an empty array when I have exceeded the post_max_size
array()
I got this from php.net but I don't understand it and don't know how to do it,
If the size of post data is greater than post_max_size, the $_POST and
$_FILES superglobals are empty. This can be tracked in various ways,
e.g. by passing the $_GET variable to the script processing the data,
i.e. , and then checking if
$_GET['processed'] is set.
This is my form,
<form action="upload.php" method="post" enctype="multipart/form-data">
<input type="file" multiple="multiple" name="file[]" />
<input type="submit" name="upload" value="Submit"/>
</form>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果
$_SERVER['CONTENT_LENGTH']
不为零且$_POST
和$_FILES
为空,则上传太大。If
$_SERVER['CONTENT_LENGTH']
is non zero and$_POST
and$_FILES
are empty, then the upload was too big.我稍微修改了 Toopay 的代码,我想你正在寻找这个。 ini_get('post_max_size') 帮助您获取允许的最大大小。
I have slightly modified toopay's code and I think you are looking for this. ini_get('post_max_size') helps you get the max size allowed.
您可以编写一个简单的尺寸验证,以避免这种情况......
You can write a simple size validation, to avoid that...
像...
Something like...