This blog should have been the first one, but somehow slipped through :-). In my early days of coding I found a nice tip to upload a large (really big) files to server with the help of .HTACCESS.
By default, PHP.INI configuration is configured to upload a max size of 2MB (security concern?), I know you can say it just mater of modifying the value in PHP.INI file and restart the server. Yes I agree, but you can do this when you own the server machine, think of a shared hosting server.
Most of the users in the world uses shared hosting compared to VPS/Dedicated server. Hence it becomes difficult to request the support to lift the limit of max-upload-size. But don’t be panic, there is a neat/simple solution this problem, APACHE makes our life easier to allow the PHP.INI value dynamically with the help of .HTACCESS. Yes, APACHE will read the configuration value from .HTACCESS file and over-write the value present in PHP.INI file.
Add the following lines to your .htaccess file (located in your DOCUMENT_ROOT) and now try to upload a file of size 20MB:
php_value upload_max_filesize 20M
php_value post_max_size 20M
php_value max_execution_time 200
php_value max_input_time 200
You might wonder why can’t we stop with upload_max_filesize? Nope, you can’t since file uploading is a part of POST method and we have to make sure:
- post_max_size is >= upload_max_filesize
- max_execution_time >= time it takes to upload upload_max_filesize file (depends on the server speed)
- max_input_time >= max_execution_time
I hope this helps for some.