Uploading Larger Files in php - php

In my site I have to upload very large files.File size may be up to 200MB.
What approach should i follow to upload these files in less duration.Is there any concept of binary uploading in php?
Any help would be highly appreciable.

Uploading large files over HTTP is obviously not perfect, which was why FTP was designed.
However, given what you have got to work with, there are a few things you can do to help make the process smoother.
Make sure that you set the appropriate settings in PHP:
max_upload_size to an appropriate size
set_time_limit(0);, so that the script does not time out.
Other settings that require tweaking:
memory_limit
post_max_size
max_input_time

1.change the max_upload_size in php.ini for appropriate size.
2.Set your script timeout to never (set_time_limit(0); in your scripts… don’t do this in your php.ini)
check these links
http://www.gen-x-design.com/archives/uploading-large-files-with-php/
http://www.sitepoint.com/upload-large-files-in-php/

Related

PHP upload settings, max file upload and chunks

My host is on a shared server so therefore i cannot change the php.ini. My goal is to upload files of upto 100mb but the servers upload_max_filesize is set to 6mb which i cannot change..
My quetsion is, is it possible to bypass this by uploading in chunks using something like https://github.com/blueimp/jQuery-File-Upload?
Many thanks in advance.
Ok I've now figured it..
By default chunking is not enabled.. you have to enable it in the jquery options, here is the source to do that https://github.com/blueimp/jQuery-File-Upload/wiki/Chunked-file-uploads
For testing purposes i've changed my php.ini settings to accept only 1mb and i'm successfully loading files that surpass that max upload.

PHP uploading files php.ini configuration

I have a question - I have a file uploader and each user is allowed to upload max_size:30M.
Now I'd like to know from your experiences what I should set up in php.ini.
Here are the options I've already changed, but I'm not sure if that is the best:
upload_max_filesize = 30M
post_max_size = 30M
max_execution_time = 300
max_input_time = 300
memory_limit = 32M
Here I think memory_limit is a bit low. And is there something more I have to include?
When I tried to upload more than 30M, Firefox crashed.
Thanks for your answers.
If you work heavily with files you should split the file and upload it in separate parts, it doesn't choke the server as much and you can check the progress, also you don't need that much memory and excecution time.
For some reason someone said it's not true... Well I don't think Youtube or upload sites like Megaupload (rip) use 2gb of memory and 2 hours of maximum excecution time to upload the file of one user, they split the file, in whatever way they can, if you need to upload 30mb files, and you use standard PHP your webserver will choke until the upload finishes, unless you don't care about that, it's not recommended.
The easiest solution is to upload it by parts, you can do it using Flash/Silverlight/JS/HTML5 or whatever way you prefer, client-side, and then joining them server-side.

move_uploaded_file file disappears from tmp but does not reach destination

I have a really odd problem. I am using an upload form to upload videos. Sometimes I have to try twice to upload a file so I know it works but these files take a long time to upload so I don't want the end-user getting mad if the process fails. Also, this works 100% of the time on my test machine so I am thinking there is a config problem.
The file is 330mb and I set upload_max_filesize and post_max_size to 500mb. The max_execution_time and max_input_time are set to 60000 for testing purposes. memory_limit is what I think may be the problem. It is set to 128mb. Does it need to be higher to have a consistent upload success rate? Anybody know of any other problems that could cause things to go wrong?
You're right in assuming memory_limit is your culprit.
Taken from php.net.
post_max_size (int)
Sets max size of post data allowed. This setting also affects file upload. To upload large files, this value must be larger than upload_max_filesize.
If memory limit is enabled by your configure script, memory_limit also affects file uploading. Generally speaking, memory_limit should be larger than post_max_size. When an integer is used, the value is measured in bytes. Shorthand notation, as described in this FAQ, may also be used. (...)

Is there any way to Upload Video Files using PHP?

I want to upload and store video files to my server using PHP. Could any one please provide me some example about how to upload a large file using PHP?
Please keep in mind that these files are generally larger than 200 MB.
I think the question is fairly limited, is it the post size where there are problems? Uploading files of this size, really should be handled by something else than the normal upload control. You should see if you can give the user a progress on the upload, because otherwise users probably will cancel the upload if it takes too long.
First hit on google: Google search
http://bluga.net/projects/uploadProgressMeter/
Look at this move_uploaded_file, but if it's so big, it needs to be allowed in php.ini to upload this big files. And maybe you will have problem with Apache as well, because default time when it disconnects you is 5 minutes.
You will need to edit PHP.INI and change those two parameters:
upload_max_filesize = 500M
post_max_size = 500M
...for a maximum upload filesize of 500MB.
If you have a properly set-up server you can put php.ini files into your htdocs root, and it will be effective.

Can file uploads time out in PHP?

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!
You need a proper value for the following php.ini settings:
max_input_time (not max_execution_time!)
upload_max_filesize
post_max_size
and maybe
memory_limit
There are some configuration directives that can cause large uploads to fail if their values are too small:
PHP
max_input_time   Maximum time in seconds a script is allowed to parse input data, like POST, GET and file uploads
upload_max_filesize   Maximum size of an uploaded file.
post_max_size   Maximum size of post data allowed.
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.
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.
I was able solve this problem using the following settings, you could use different values but you get the idea:
For my server, I put these lines in a ".user.ini" file inside the script directory, your server may look for a different file, if you do a phpinfo('user_ini.filename') on the server it will spit out the file you need to put your values in
max_execution_time = 1800
max_input_time = -1
post_max_size = 100M
upload_max_filesize = 100M
memory_limit = 256M
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().
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.
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.
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.
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.
If changing any of the above parameters doesn't seem to make any difference, it can be that a html form somewhere contains the name MAX_FILE_SIZE as a hidden field.
<input type="hidden" name="MAX_FILE_SIZE" value="10000000">
In the example above, any file over 10MB will not be uploaded.

Categories