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

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?


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
}
  • http://nginx.org/en/docs/http/ngx_http_core_module.html#client_max_body_size
  • http://nginx.org/en/docs/http/ngx_http_core_module.html#error_page

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