1

i want to upload a local file via PHP to Google Drive. If I upload a small file (<5MB) everything is working. If I want to upload a larger file I get a "Fatal error: Maximum execution time of 30 seconds exceeded". I can set the max_execution_time in my php.ini on a very high value but it seems to be a bad solution. If I use "set_time_limit(seconds);" I can't upload more files simultaneously (I don't know why).

So my question is how to upload a large file without changing my php.ini to a bad execution time. How is that supposed to solve in PHP? I would like to use just a simple CURL cli command but that does not work with Google Drive because CURL can't support Oath.

Lotus
  • 442
  • 1
  • 3
  • 15
  • possible duplicate of [How to upload large files above 500MB in PHP](http://stackoverflow.com/questions/16102809/how-to-upload-large-files-above-500mb-in-php) – Ares Draguna Oct 29 '14 at 11:16
  • i just want to use the google drive php api. it's not the same problem. – Lotus Oct 30 '14 at 12:04

2 Answers2

2

Setting the max_execution_time with set_time_limit is the right solution. If your script takes more than 30 seconds to upload the file, it will run more than 30 seconds.

set_time_limit(600); //File upload should not take longer than 10 minutes
do_your_file_upload();
set_time_limit(30); //Change it back to 30 seconds for further processing

I can't upload more files simultaneously

Can you specify what you mean?

If you cannot reach your PHP-Script while the other one runs, it is often because of PHP session management. When you start the session with session_start PHP (creates and) opens the session file and locks it for writing. The file will be locked until your scripts calls session_write_close or the script execution ends. To work with two or more sessions simultaneously, you have to call session_write_close:

session_start();
//do stuff
session_write_close();

set_time_limit(600); //File upload schould not take longer than 10 minutes
do_your_file_upload();
set_time_limit(30); //Change it back to 30 seconds for further processing

session_start();
//do more stuff
session_write_close();
BreyndotEchse
  • 2,192
  • 14
  • 20
  • I had two identical scripts a.php and b.php running at the same time. Both of them start a session and both of them upload the same file but with different names. Both of them failed. – Lotus Oct 30 '14 at 12:01
  • Any error messages? If not, give use some code to review. – BreyndotEchse Oct 31 '14 at 09:30
0

This a bad idea to use a simple PHP code to upload a very large file.

You should use Javascript to upload large files because it's using AJAX methods. Also, it will allow you to display a progress bar.

I did a little research. Here is some nice scripts using jQuery : http://designscrazed.org/html5-jquery-file-upload-scripts/

Or another script which not use jQuery (I don't if it's a good one) : http://igstan.ro/posts/2009-01-11-ajax-file-upload-with-pure-javascript.html

Good luck !

  • That's simply not what i want. I want to upload a file to Google Drive. Therefore i need to use Googles APIs. The script is also running on a server with no browser. That's why i can't use javascript (there is no offline access in js api). – Lotus Oct 30 '14 at 11:57