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

后端 未结 6 1373
没有蜡笔的小新
没有蜡笔的小新 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:08

    Per the PHP documentation:

    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.

    If you need the limit increased for a specific script, you can try ini_set('post-max-size', $size_needed);. I'm not sure if it can be overridden within a script, though; that limit is probably there to specifically keep you from doing what you're trying to do.

提交回复
热议问题