How to upload large files above 500MB in PHP [duplicate] - php

This question already has answers here:
upload large files using php, apache
(5 answers)
Closed 9 years ago.
I made an upload page in PHP, but I dont know why the page would not upload documents greater than 500MB, This is my first time of trying to upload something that large, I changed all the configurations in the PHP.INI (post_max_size = 700M, upload_max_filesize = 600M, and max_execution_time = 300). The codes for upload is as below
if(isset($_FILES['upload']) && !empty($_FILES['upload']['name'])){
move_uploaded_file($_FILES['upload']['tmp_name'], $this->filePath.$this->fileName);
}
I need help, I wonder if there is something am not doing right..

Do you think if increasing upload size limit will solve the problem? what if uploading 2GB file, what's happening then? Do you take into consideration the memory usage of such a script?
Instead, what you need is chunked upload, see here : Handling plupload's chunked uploads on the server-side
and here : File uploads; How to utilize "chunking"?

By configuration, PHP only allows to upload files up to a certain size. There are lots of articles around the web that explain how to modify this limit. Below are a few of them:
PHP Increase Upload File Size Limit
How do I increase the PHP upload limits?
Uploading large(big) files in PHP using .htaccess
For instance, you can edit your php.ini file and set:
memory_limit = 32M
upload_max_filesize = 24M
post_max_size = 32M
You will then need to restart apache.
Note:
That being said, Uploading large files like that is not very reliable. Errors can occur. You may want to split the files, and include some additional data for error corrections. One way to do that is to use par recovery files. You can then check the files after upload using the par command line utility on unix-like systems.

I assume you mean that you transferring the files via HTTP.
While not quite as bad as FTP, its not a good idea if
you can find another of solving the problem.
HTTP (and hence the component programs) are optimized around transferring relatively small files around the internet.
While the protocol supports server to client range requests,
it does not allow for the reverse operation. Even if the software at either end were unaffected by the volume, the more data you are pushing across
the greater the interval during which you could lose the connection.
But the biggest problem is that caveat in the last sentence.

Related

Can't upload large file in Laravel (php.ini settings are correct in my opinion)

I have the following problem in Laravel.
I would like to upload a file through a form. But for some reason if the file is larger than around 2100 KB, the validation fails, and says that the file is 'required' and I did not provide it.
I've read numerous articles, that this can be because of php.ini settings. On my server they are the following:
upload_max_filesize 64M
post_max_size 64M
These values are copied from the output of phpinfo(), so they are in effect.
And despite this, the upload fails even for a 2 MB file. Do you have any ideas what I could check/set to solve this?
I am using laravel 5.2, and PHP 7.
Check which server software you are using. Nginx for instance has it's own limit (default set to 1MB I believe). Apache might have it too. Consult the respective manuals for those packages on how to configure them. Or if you're using shared hosting, contact support to see if they can increase the limit.
Though this isn't a really scalable solution. Next time you might want to upload a 100MB file, and you probably don't want to allow 100MB requests on your servers. A better approach would be to split the file in smaller chunks in the frontend, with JavaScript, and submit them as parts of the same upload, then recombine the parts on the server once the file is completely uploaded. Beware of additional checks you'll have to do here though.
You might want to incorporate the following into your own code:
<?php
//--- this tries to override the default of only 2M file uploads.
ini_set("upload_max_filesize","25M");
ini_set("max_execution_time",600); //--- 10 minutes
ini_set("post_max_size","35M");
ini_set("file_uploads","On");
?>
In my case, it was HDD space issue. not enough space to store the file.
Laravel should handle it with proper message, instead of indicating user didn't upload anything.
If you are not using any other package to upload files to check , then
then remember to restart apache .

Debugging techniques for a PHP script with many, many file uploads?

I have a PHP script which services a form that contains many, many file uploads. There's about 40 separate files being uploaded, although each one is less than 30 KB in size (so about a meg, total of actual data is being transfered).
I'm using CakePHP for this, if it somehow makes a difference.
The problem I'm having is that only 19 of the files are being uploaded (once they're uploaded I send out an email using GMail as an SMTP relay). I've checked the obvious things, such as listed here:
Can file uploads time out in PHP?
And I've got generous values for everything.
Could anyone suggest strategies to use for running down this problem and/or specific things to check?
I don't think it is a CakePHP issue. Apache and php have certain limits on number of files and max size of files that can be uploaded at a time. Also there will be max post size.
There are two ways to overcome this
You can override the settings in .htaccess file like
php_value upload_max_filesize 10M
php_value post_max_size 15M
php_value max_file_uploads 50
Change it in php.ini file and restart server.
So after much, much digging it looks like it was a problem with my SMTP setup. I couldn't tell you how or why, but the problem was that attempting to email a zillion emails (well, ~40) caused the PHP process to halt (no error messages, nothing). Running the exact same code under XDebug worked fine, and putting a quarter-second sleep() after each email appears to work.
(On a semi-related note: Is there a way to delete a StackOverflow question that you've asked? :) )

The maximum file size uploaded using PHP and html5?

Any idea on how big the file size could one file uploaded using php and html5?
And
Is there any suggestions on good components or example to do this?
thanks a lot!
On the server side the maximum upload size is limited by php post_max_size and upload_max_filezize.
Also your webserver can limit the maximum size of your post body. E.g. Apache limitrequestbody which defaults to 0 = unlimited or nginx client_max_body_size which defaults to 2MB
If you are planning to upload large files using html5 you might want to have a look at file.slice which is supported by all modern browsers
Support for .slice in the File API
Firefox supports the Blob API and the .slice APIs that come with it. This can help people who want to process parts of large File objects from JavaScript without having to load the whole file into the memory. People who reliably upload large files can use some server and JS code to split a large file into sections and upload chunks, including re-retrying failed sections, or even uploading several sections, in parallel.
Using this, you could upload giant files in chunks and merge them on the server-side again.
EDIT
Found this great article which explains html5 uploads by streaming via xhr
http://www.webiny.com/blog/2012/05/07/webiny-file-upload-with-html5-and-ajax-using-php-streams/
This procedure has a very low memory footprint, you might still run into the webserver and php upload limits because this is done with a single request. The code should give you an idea on how the whole technology works.
PHP's pretty crappy when it comes to large file uploads, particularly because you have to a memory limit higher than the size of the file. As well, Apache on 32bit systems tends to have a 2gig file limit itself, so even if PHP could handle the upload, Apache will choke.
You need to set the value of upload_max_filesize and post_max_size in your php.ini :
; Maximum allowed size for uploaded files.
upload_max_filesize = 40M
; Must be greater than or equal to upload_max_filesize
post_max_size = 40M
If you can't change your php.ini, you're out of luck. You cannot change these values at run-time; uploads of file larger than the value specified in php.ini will have failed by the time execution reaches your call to ini_set.
See the Description of core php.ini directives.
The maximum size of an uploaded file is integer.
When an integer is used, the value is measured in bytes
The maximum file size value is defined in phi.ini file.
search this in php.ini
Maximum allowed size for uploaded files.
upload_max_filesize = 32M

php file upload size question

I know you can control the size of uploads in PHP using $_FILES['userfile']['size'] > XXX
My question I suppose is performance related.
When you upload a file, my understanding is the whole file gets uploaded to a temporary location, and then you have access to $_FILES
What happens if a user attempts to upload a 10gb file? (as an example of a very large file)
If a large file is attempted to be uploaded, does this waste server bandwidth as the file needs to be uploaded before it can be processed/validated.
I know PHP has like timeouts etc but I'm curious if there is a performance impact from users attempting to upload very large files, even if (for example) the max file size is 2mb.
Is this a concern or something unavoidable and just to not worry.
Thanks.
Both apache and php have max-post limitation to prevent such behavior.
from php.ini:
; Maximum allowed size for uploaded files.
upload_max_filesize = 4M
; Maximum size of POST data that PHP will accept.
post_max_size = 8M
Actually, the [size] isn't there for control, it's simply the size of the uploaded file. By the time your script gets fired up to check that, PHP (and the webserver) have already handled the uploaded and applied their own internal limits (Apache's LimitRequestBody, PHP's upload_max_size, etc...).
PHP will allow all uploads to proceed, if they've been enabled via the file_uploads INI setting. Since you can't really trust the client, the client-provided size will be ignored and the upload will proceed until it either completes or hits the upload limit. So, yes, it can waste your bandwidth.
If you allow uploads, then it can be abused. But, there's no real difference between someone uploading a 10gig file or someone doing a POST with 10gig of bogus data. Either way, you've got 10gig of data coming your way.

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.

Categories