title: PHP: What is a good way to upload multiple large files?
body: <h2>What is a good way to upload multiple large files in PHP?</h2>
  <p><strong>Note:</strong> in my case I don't really need very large files, I need something like 40-50 or maybe 100 MB upload. My purpose and goal is mainly about documents upload in websites, these documents (pdf, doc, etc.) can sometimes be 20-30 MB and rarely 100+MB, where normally the php MAX_UPLOAD_FILESIZE is 10-20 MB. I think that having a large MAX_UPLOAD_FILESIZE is very bad and anyway allowing large file uploads in PHP (like 1GB+) is really a bad idea.</p>
  <p>I have been reading, even here on SO, different solutions like <strong>plupload</strong> and some others (HTTP Upload, bigUpload, etc.) and I am not sure which way is better to consider.</p>
  <p>As a principle, I'd like to find something with <strong>mantained code</strong> (not an abandoned library) and possibly following coding standards (PSR).</p>
  <p>I think that writing all from scratch would be a huge work, but maybe I am wrong, if someone did that I would like to hear your experience. Of course if I can't find something that gives me what I need, I'll have to edit existing libraries or write one on my own.</p>
  <p>I will give a try to plupload but my biggest concern is that it might not be well mantained. There is a v3 release but the stable is still the v2. If I understand correctly, the last updates of this library on GitHub were made in 2017 and this doesn't really reassure me. PHP but everything in general changes really quickly.</p>
  <h3>Problem 1: Server knows the size of the file only when the upload is finished</h3>
  <p>I think this is the first problem. I can't be sure about the file size until the upload is completed. If I have to give an error in PHP because the file is too big, I'd need to upload the file before. I could guess the size in javascript but I think that would be too hackable. Same thing for HTML5. All client-side checks could be "hacked" or manipulated even if it requires work, it is still doable</p>
  <h3>Problem 2: File chunking, is it the best solution?</h3>
  <p>I have read about file chunking, which is very interesting, but that is only client-side, right? Because to chunk a file on server-side, you go back to problem 1, you need to upload the whole file before chunking it. Is client-side chunking safe? Are there known vulnerabilities about it? (an example, could I exploit something out while the file is being uploaded?). I will read more about this later.</p>
  <p>Also what about the time required to upload? Let's say you are using your phone in 4G to upload two PDFs or JPGs on a form, you have to upload 20-30 MB with a bad signal in that moment, let's say you take 30 seconds or 1 minute to upload them. Will the server stop listening after a while?</p>
  <p>In any case, with file chunking, do I need to have a large MAX_FILESIZE_UPLOAD? Is usually the request sent (as a POST) with the entire file, which could return an error because the size exceeds the PHP limit? I would like to keep a normal PHP file size limit.</p>
  <h3>Problem 3: stopping file upload and deleting interrupted upload</h3>
  <p>What happens if I stop or I want to stop my upload? I guess that the server will find itself with a temporary file which is only partially uploaded.</p>
  <p>Then, in general, is the best way to have a cron checking the /tmp (or whatever) folder and deleting uncompleted files?</p>
  <h3>Problem 4: overwriting interrupted uploads</h3>
  <p>What if the user uploads a new file that should overwrite the old one, but the old one was not completed? Let's say, user uploads a 10MB document but realizes it's the wrong one. He will probably reload the page or maybe click "Browse" again and upload the new one. So, all the temporary files should have a unique name. If I remember correctly, PHP already gives them a random name in /tmp/. Is this enough? Would it be better to manually give them a random name, maybe based on a timestamp?</p>
  <p>In code words, something like:</p>
  <code>$fileName = time() . '-' . uniqid() . '.tmp';</code>
  <p></p>
  <h3>Problem 5: what about multiple files upload?</h3>
  <p>Let's say the user uploads 3 documents, 10 MB each one. Should the server receive them all at the same time or one by one? Or maybe is it the same? At a first look, I might think that multiple uploads at the same time could give more problems with server load. Maybe this is not that important though.</p>
  <h3>Problem 6: accessibility</h3>
  <p>Would all this be easily accessible? Do you think that a user using a screen-reader would be able to upload multiple (and possibly large) files without problems?</p>
  <h3>Conclusion</h3>
  <p>In conclusion I will take a look at existing libraries and test a bit if I can find a good solution for my needs. In general I would like to read comments or experiences that could  help me understand possible difficulties and problems that I could encounter.</p>