Three things to do for File upload using PHP and Apache

Recently I have been ask by a developer to check the Apache configuration as his PHP script is not able to upload files more than 512KB. I looked around with my basic knowledge to see whats the cause of problem. And found these three things need to be modify in order to correctly upload file using PHP with Apache Webserver.

1) Check the php.ini for
upload_max_size it must be greater than what you required for example to upload 10 MB file you need

upload_max_size 10M in PHP.ini


php_flag upload_max_size 10M in .htaccess (it will only work if Apache is not using SUExec , not sure why is it so)

2) Check the PHP.ini for post_max_size

in PHP.ini it should be
post_max_size 11M ( as you will be having some text field with your 10 MB file so make space for them, it should always be greater than upload_max_size otherwise you are not able to upload full size files )

3) Its not necessary is set by default. And not sure whats its default value, but if you are getting this error in your Apache Error log

Requested content-length of xxx is larger than the configured limit of xxx, referer:

than you need this in your httpd.conf file

<Files *.php>
SetOutputFilter PHP
SetInputFilter PHP
LimitRequestBody 11534336

this will set the PHP to have upload 11MB of body text, and header is not counted here. Again this must be set great than upload_max_size setting for php.ini

Now you can upload any file upto 10MB on your server.

Enjoy file uploading …

Sumit Gupta