TechnoKida is Technology and Social Media Blog Platform. We write blog about Web Development Tutorial, Social Media and Trending Updates to help people who want learn Online.

How to Upload Large Files On Server Using PHP



File upload is very easy but sometimes you needed to Upload Large File Using PHP. In this lesson, you will get knowledge about How to Upload Large File Using PHP.

One of the most famous uses is media/image uploads. Your users can submit photographs from a form without FTP.

By default, PHP allows a maximum file upload of 2MB. You can ask users to resize their images before uploading but let’s face it, they will not. Happily, we can increase the limit when necessary.

In PHP there are two configuration options to handle the maximum file upload size.
  • upload_max_filesize
  • post_max_size
We can change these both sizes to our requirement. Let we change the filesize to 20MBs.

You have to take care about upload time. If you want to allow maximum file upload size to 20MBs then sometimes it will take more time to upload. Normally PHP scripts timeout after 30 seconds so you have to increase it to 300 seconds, it means almost 5 minutes, so you have to change in these below two values of parameters.
  • max_input_time
  • max_execution_time
To change these settings, you have two options
  1. change php.ini configuration file
  2. .htaccess file of the application.

1.change php.ini configuration file

You just have to find out that variable and increase the value and restart the server, That’s it.

2..htaccess file of the application.

Open the .htaccess file and write down below code, save it and restart the server.

php_value upload_max_filesize 20M
php_value post_max_size 20M
php_value max_input_time 300
php_value max_execution_time 300

Finally, you can define the constraints within your PHP application:

ini_set('upload_max_filesize', '20M');
ini_set('post_max_size', '20M');
ini_set('max_input_time', 300);
ini_set('max_execution_time', 300);

PHP also provides a set_time_limit() function so you don’t need to set max_execution_time directly.
Setting the options in your PHP code is possibly more practical since you can extend the execution time and increase the file size when your application is expecting a large upload. Other forms would revert to the default 30-second time-out and 2MB limit.


Please read our other PHP tutorials, Write your comments.

1 comment:

  1. Allergies are unpleasant, uncomfortable and troublesome. Fortunately, there are some great tips available that can help sufferers to combat their troublesome symptoms. This article has introduced several effective measures that can help with the sniffles, play bazaar satta king

    ReplyDelete