Search code examples
phpcodeigniteruploadlarge-fileshttp-status-code-413

413 Request Entity Too Large, using CodeIgniter: phpinfo() indicates proper max size


When using the upload functionality in CodeIgniter, if I try to upload a pdf file that is larger than 20M, I either get a "404 file not found" or a 413 Request Entity Too Large. I can see that it is "Uploading nn%", up to about 97% or 98% and then it quits and gives me an error. If I echo phpinfo(), I can see the following:

upload_max_filesize = 64M  
post_max_size = 256M  

Also, if I use the File Manager on the cPanel, I am able to upload larger files with no problem.

I put the following in the .htaccess file (which was suggested on another question), but it hasn't helped:

<IfModule mod_php5.c>  
    php_value upload_max_filesize 128M  
    php_value post_max_size 128M  
    php_value max_input_time 3600  
    php_value max_execution_time 3600  
</IfModule>   
<IfModule mod_php4.c>  
  php_value upload_max_filesize 128M  
  php_value post_max_size 128M  
   php_value max_input_time 3600  
   php_value max_execution_time 3600  
</IfModule>   

I am fairly new to PHP.


Solution

  • It looks like the error is coming not from PHP but from a web server.

    If you're using nginx, you could up the max allowed post size with client_max_body_size directive

    server {
        ...
        client_max_body_size 128m
        ...
    }
    

    If you're using Apache, then there are a couple of options to check for in its config file (httpd.conf).

    LimitRequestBody 131072000
    

    If mod_security module is used in Apache, update limit for it as well:

    SecRequestBodyLimit 131072000
    

    Don't forget to restart the server.