23

I'm trying to upload large files to my server (my server support post_max_size 192mb and max_execution_time 600 sec). When I upload 100mb files execution will stop after 600 sec so files are not uploaded to the server. How can I increase max_execution_time in PHP (only for the file uploading process)? I have tried:

ini_set ( 'max_execution_time', 1200); 
if(move_uploaded_file($_FILES['Video']['tmp_name'],$tmppath)) {
  // ...
} 

Any ideas how I can overcome this?

4
  • 1
    What exactly happens after 600 seconds? Which error message do you get? Upload time doesn't count against the PHP time limit
    – Pekka
    Commented Jan 5, 2012 at 14:29
  • 2
    Try set_time_limit()
    – bfavaretto
    Commented Jan 5, 2012 at 14:30
  • @Ajay Chthri: for uploading some large size files you can try with some uploader like java applet uploader Commented Jan 5, 2012 at 15:04
  • same problem with me.. and it gives me "page not found" error.. i am inserting file names into a table from another table.. i am doing this in Codeignitier.. please help me
    – saadk
    Commented Jul 23, 2015 at 17:24

5 Answers 5

39

Add this to an htaccess file (and see edit notes added below):

<IfModule mod_php5.c>
   php_value post_max_size 200M
   php_value upload_max_filesize 200M
   php_value memory_limit 300M
   php_value max_execution_time 259200
   php_value max_input_time 259200
   php_value session.gc_maxlifetime 1200
</IfModule>

Additional resources and information:


2021 EDIT:

As PHP and Apache evolve and grow, I think it is important for me to take a moment to mention a few things to consider and possible "gotchas" to consider:

  • PHP can be run as a module or as CGI. It is not recommended to run as CGI as it creates a lot of opportunities for attack vectors [Read More]. Running as a module (the safer option) will trigger the settings to be used if the specific module from <IfModule is loaded.
  • The answer indicates to write mod_php5.c in the first line. If you are using PHP 7, you would replace that with mod_php7.c.
  • Sometimes after you make changes to your .htaccess file, restarting Apache or NGINX will not work. The most common reason for this is you are running PHP-FPM, which runs as a separate process. You need to restart that as well.
  • Remember these are settings that are normally defined in your php.ini config file(s). This method is usually only useful in the event your hosting provider does not give you access to change those files. In circumstances where you can edit the PHP configuration, it is recommended that you apply these settings there.
  • Finally, it's important to note that not all php.ini settings can be configured via an .htaccess file. A file list of php.ini directives can be found here, and the only ones you can change are the ones in the changeable column with the modes PHP_INI_ALL or PHP_INI_PERDIR.
4
  • Or just change these values directly in your php.ini file. Commented Apr 21, 2016 at 10:43
  • @jeremy Harris, that edited link is now a dead end. Please update that...
    – MwamiTovi
    Commented Jan 14, 2020 at 8:03
  • The link you edited it with gives a 403 forbidden error. I will try to find another resource. Commented Jan 14, 2020 at 13:06
  • I just updated this answer with a bunch more relevant information since it seems to still get a lot of viewers even almost a decade later. Commented Feb 1, 2021 at 19:01
6

Theres a setting max_input_time (on Apache) for many webservers that defines how long they will wait for post data, regardless of the size. If this time runs out the connection is closed without even touching the php.

So your problem is not necessarily solvable with php only but you will need to change the server settings too.

3
  • just now i check my server support max_execution_time 30 mints but when i upload file 30 mb file process will stop after 10 mints (querys are not excute) Commented Jan 5, 2012 at 15:20
  • It's not the execution time you need to worry about, it's the input time. If you could upload those 30mb in less than 10min it would run. If you would upload only 200kb and need 11 min for it it wouldn't run too. It's not depending on you filesize or execution time at this moment, it's depending on the time you need to upload the file.
    – bardiir
    Commented Jan 5, 2012 at 15:26
  • 1
    so we need increase to max_input_time ? Commented Jan 6, 2012 at 5:33
2

Is very easy, this work for me:

PHP:

set_time_limit(300); // Time in seconds, max_execution_time

Here is the PHP documentation

0

For increasing execution time and file size, you need to mention below values in your .htaccess file. It will work.

php_value upload_max_filesize 80M
php_value post_max_size 80M
php_value max_input_time 18000
php_value max_execution_time 18000
0
// Karvy master upload module
function uploadKarvyData()
{
    ini_set('MAX_EXECUTION_TIME', -1);
    ini_set('memory_limit', '-1');  
    or
    ini_set( 'memory_limit', '1024M' );
    ini_set('upload_max_filesize', '1024M'); 
    ini_set('max_input_time', 360000);  
    ini_set('max_execution_time', 360000);
}
1
  • I am sure it would help the community if you explained to us why your code would solve the OP's problem Commented Jan 14, 2022 at 15:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.