tags:

views:

1910

answers:

9

Hi im quite new to PHP, i have created a form for very large csv files to be uploaded to my server. Some one mentioned to me that the browser can time out due to the uploading file being to big, is this true? and if so, can it be prevented?

Thanks for your help!

A: 

Yes it is true. File upload is done through a POST request and requests in general are subject to timeout. You should be able to reconfigure your environment for a longer request timeout.

Ates Goral
+1  A: 

A script is allowed to run, by default, for something like 30 seconds. You can use the set_time_limit() function to alter this. Also, if your user will need to upload large files, you'll need to change the post_max_size and/or the upload_max_filesize values in your php.ini file.

Also, if you want to just extend your timeout limit globally, you can change max-execution-time in php.ini.

Jess
brilliant, thanks for that! i didnt even know about post_max_size or upload_max_file_size! very much apreciated
Ben McRae
+12  A: 

You need a proper value for the following php.ini settings:

  1. max_input_time (not max_execution_time!)
  2. upload_max_filesize
  3. post_max_size

and maybe

  1. memory_limit
Ionuț G. Stan
A: 

It's not just timeouts that can cause problems. There are some limits on the maximum size of file that can be uploaded. These limits can be changed in the php.ini file:

post_max_size
upload_max_filesize memory_limit

Check out http://uk.php.net/ini.core for details.

macleojw
+6  A: 

There are some configuration factors that can cause that an upload is interrupted:

PHP

Apache

  • TimeOut   Amount of time the server will wait for certain events before failing a request
  • LimitRequestBody   Restricts the total size of the HTTP request body sent from the client

There are probably some more than this.

Gumbo
i have no idea where abouts to even go to edit the apache settings :(
Ben McRae
Ask your provider if these settings are proper to upload large files.
Gumbo
+1  A: 

When uploading very large files, you have to change 4 configuration variables:

  • upload_max_filesize
  • post_max_size
  • memory_limit
  • time_limit

Time limit may be increased at runtime with set_time_limit().

vartec
+2  A: 

A good way to work around the poor handling of large file uploads in php, is to use an uploader like JUpload which will split the file into chunks before sending them. This also has the benefit for your users that they get a proper progress feedback while uploading, and they can upload multiple files in one go.

Ronny Vindenes
A: 

Does the PHP download has the same problem?

I tried to use PHP copy() function to get a large amount data--a lot of files about 5 to 6 K each. It seems I can not copy them all at a time.

A: 

My answer is not directly related to your original question, but if you have a reverse proxy load balancer in front of your PHP script, the load balancer can timeout or block large uploads. Always check your load balancer's configuration if you support file uploads. Just like PHP, most load balancers default settings for uploads are pretty small.

Cory R. King