开发者

Proper way to detect that post_max_size was exceded in php? [duplicate]

This question already has answers here: How to gracefully handle files that exceed PHP's `post_max_size`? (6 answers) Closed 7 y开发者_开发百科ears ago.

What is the proper way to detect that post_max_size was exceded in php? It looks like I can only check for an empty $_POST array, which seems imprecise. I need to detect if a file that was uploaded was to big and produce a proper error message.


You can't, if the value of post_max_size is exceeded, super globals will be empty.

A solution is to add in your form a $_GET variable

<form action="check.php?shouldHaveFilesInHere">

and to check if other super globals are filled or not in check.php.

http://www.php.net/manual/en/ini.core.php#ini.post-max-size


If you want to know if the file that was uploaded is too large you should use $_FILE['error'].

http://php.net/manual/en/features.file-upload.errors.php

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜