How to detect if a user uploaded a file larger than post_max_size?

后端 未结 6 1383
没有蜡笔的小新
没有蜡笔的小新 2020-12-06 12:00

How should I go about handling http uploads that exceeds the post_max_size in a sane manner?

In my configuration post_max_size is a few MB

6条回答
  •  被撕碎了的回忆
    2020-12-06 12:24

    Unless your upload form has fields other than the file input field, then $_POST should be empty - files are handled exclusively through the $_FILES. It's very odd that $_FILES would be empty if the post size is exceeded - the upload handlers have a specific error code (1/UPLOAD_ERR_INI_SIZE) to report such a condition. Also check that memory_limit is larger than the upload_max_filesize.

    Your webserver may be blocking the upload as well, which would occur before PHP is invoked. On Apache, it's controlled by LimitRequestBody.

提交回复
热议问题