How to detect if post_max_size triggered?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • MagicMyth
    New Member
    • Aug 2006
    • 2

    How to detect if post_max_size triggered?

    Hi all, I’m creating a site that allows file uploads to registered users. I’ve got a system in place where if the user uploads a overly large file that it would automatically warn them off the offence and keep a record of it, if it was way over the file size limit I allow for (naturally the file is destroyed as well). If they continued to try to upload large files they would receive a temp ban. This relies on the system being able to determine how big the file was as I cannot simply punish a legit user who simply goes a little over the file size (that just wouldn’t be very nice :) ). Now if the file they uploaded was greater than upload_max_file size the file size information would be 0 but I could still determine that this limit was reached thanks to the $_FILES['file’]['error'] array and take appropriate actions.

    Unfortunately I discovered recently that if post_max_size was triggered then php just totally wipes out both $_POST and $_FILE globals and seems to pass absolutely no errors back to the script making it totally impossible to determine if someone keeps trying to upload massive files eating into my bandwidth.

    Heres what I found from the php manual:
    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. <form action="edit.ph p?processed=1"> , and then checking if $_GET['processed'] is set.
    Their suggested method of tracking the event is not useful to me as a legit user could get punished if they somehow accidentally put this query string into their URL.

    I noticed though that if post_max_size is exceeded then it gets recorded in the php.log, so php must be outputting something.
    Sorry if my post has been a bit long winded but any suggestions on how I can detect if post_max_size was triggered?
  • vssp
    Contributor
    • Jul 2006
    • 268

    #2
    Please chage php.ini file and set the maximum uploaded file size and restart the server then check the program

    Comment

    • MagicMyth
      New Member
      • Aug 2006
      • 2

      #3
      Afraid that doesn’t do me any good.
      I’ve tried before setting the upload_max_file size smaller than post_max_size which you would think would cancel the connection and report the upload_max_file size exceeded error before post_max_size was reached but it seems so long as the file being uploaded is at least the size of post_max_size then post_max_size is triggered and all $_POST information wiped out even if upload_max_file size lower size threshold was reached way before post_max_size was.
      I just want to know when post_max_size has been reached from within my script.
      Below is what I get in my php log when I have upload_max_file size set to 4mb and post_max_size set to 8mb:
      PHP Warning: POST Content-Length of 8750362 bytes exceeds the limit of 8388608 bytes
      Is their a way of catching this error report from within my php script?

      Comment

      Working...