Limit upload file size and redirect user to error page if limit exceeds

12,476

Solution 1

You should be able to do this using something like:

server {
  server_name example.com;

  client_max_body_size 10m; # or whatever size limit you want
  error_page 413 /custompage.html; # you can also use a named location here if you like
}

Solution 2

Don't forget to set post_max_size and upload_max_filesize to corresponding value in php.ini.

Share:
12,476

Related videos on Youtube

jonny
Author by

jonny

Updated on September 18, 2022

Comments

  • jonny
    jonny over 1 year

    Is it possible to redirect user to file file too big page

    when POST request size exceeds specified limit?

    I am aware about max-request-size option, but it gives just static page that cannot be overloaded.

    I am thinking to create a rewrite rule which takes

    content-size from request body as input and redirects to error page

    UPDATE

    now we use nginx as front-end. Any new suggestions?

  • rvs
    rvs over 12 years
    but this won't work with most of modern browsers - unfortunaley they can't handle 413 properly. So, I'm afraid there's no solution to this problem (well, unless you can patch all current browsers)
  • kolbyjack
    kolbyjack over 12 years
    You can change the status code to anything else with error_page if you don't want to actually return 413 to the client. error_page 413 =403 /custompage.html; will use 403, for example.
  • jonny
    jonny over 9 years
    We are not at php.