Upload large(Big) files in PHP using .htaccess
- Date: Feb 16, 2010
- Author: Rakshit Patel
- Comments: 12
- Tags: .htaccess for php.ini, .htaccess rules for increase upload limit, .htaccess tricks, Helpful tips, How to upload big files, Increase upload file size limit, PHP configuration, PHP Programming tips, set php configuration values, Upload larger files in PHP, working with larger files upload
- Categories: .htaccess, Common Issues/Bugs, Helpful Tips and Tricks
I have seen many developers who find difficulties when working with larger files upload in php. When files which are too large in size, needs to be uploaded by php than you have to change the default file size either from php.ini OR httpd.conf OR using .htaccess. Default upload file size will be 2MB. If you are uploading file which is larger than 2MB size than here i am showing you the way to upload larger files using PHP.
As i told there are three ways to do this task which are below.
When you are working in localhost than you may change and increase the upload file size limit using any of the above. But the best way is to do with .htaccess as when your site will be on server than you may not have access of php.ini and httpd.conf. You can make .htaccess file , write the below rules and you will get the solution to increase the upload file size.
Below is the rules of htaccess using which you can use to upload a large file using file field of the form and copy() OR move_uploaded_file() function in PHP.
php_value upload_max_filesize 32M
php_value post_max_size 32M
php_value max_execution_time 360
php_value max_input_time 360
That's it. Now you can upload the file with size up-to 32MB.
In the above .htaccess rules,uploading capability is increased by above rules which are explained below.
Rule 1: upload_max_filesize sets maximum file size for uploading.
Rule 2: post_max_size sets maximum size of the post data.
Rule 3: max_execution_time sets maximum time in seconds a script is allowed to run before it is terminated.
Rule 4: max_input_time sets maximum time in seconds a script is allowed to parse input data of HTML form.
You can set the value of these parameters as per your file size.
You can also set these values from php.ini or httpd.conf file by searching these name and increase the size limit as per your needs.