Looking to Build/Redesign a Website or Blog ?

To speak to Rakshit, call +91 968 704 2303

Upload large(Big) files in PHP using .htaccess

Hello Friends,

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.
    1) .htaccess
    2) php.ini
    3) httpd.conf

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.

To know more about programming,JavaScript issues,jQuery,Expression Engine,MYSQL database and Open-source, enter your email address below. We will send you free tutorials.

Enter your email address:
 
Feel free to ask any question. Just leave your comment below and we will answer your comment with in 24 hours.
Share:

12 Comments

  • Upload large(Big) files in PHP using .htaccess…

    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…

  • Upload large(Big) files in PHP using .htaccess…

    When files which are too large in size, needs to be uploaded by php than change the default file size either from php.ini OR httpd.conf OR using .htaccess. Default upload file size will be 2MB.Hire PHP Programmer Ahmedabad,Hire PHP Developer India,Raks…

  • Joseph

    First, thank you for the tutorial.  It is well written and will apply in most circumstances.
    My issue is that on my site's shared hosting account, the ability to override the server-wide PHP settings via any of the methods above has been disabled.  I am therefore stuck.  Thankfully, I found a perl script that will upload the file(s), and then repost the information to a PHP script.  It is fairly simple to use.  You can view it here:  http://www.raditha.com/megaupload/upload.php.
    You will need to know a little perl in order to make it work, but it is actually rather straightforward and easy to understand and implement.

  • Joseph

    First, thank you for the tutorial.  It is well written and will apply in most circumstances.
    My issue is that on my site's shared hosting account, the ability to override the server-wide PHP settings via any of the methods above has been disabled.  I am therefore stuck.  Thankfully, I found a perl script that will upload the file(s), and then repost the information to a PHP script.  It is fairly simple to use.  You can view it here:  http://www.raditha.com/megaupload/upload.php.
    You will need to know a little perl in order to make it work, but it is actually rather straightforward and easy to understand and implement.

  • Thank You for the tutorial. This few but very important lines of code in .htaccess file solved my problem with uploading large files on my server.
    Regards 🙂

Leave a Reply

Your email address will not be published.