简体   繁体   中英

php upload very large file best practice

There are many questions with this title , but no one helps. My application should handle file uploads with size up to 2 GB and it should be done through a browser , not something like a FTP file uploader.
I'm aware of configuration settings should be done for example on php.ini . but there are some questions in my mind :

  1. Is something like uploadify library a good solution for this file size or there are better alternatives?

  2. because of the big size , maybe this is desirable to have pause/resume functionality in it. is it possible to implement this functionality through HTTP file transfer via a browser? if yes , how to?

  3. some people talk about some type of vulnerabilities like DOS ATTACKS . is it in this case a serious issue and what are the considerations for this types of attacks?

if there are any extra recommendations and suggestion , please tell me about them.

UPDATE: some have suggested to do the job using FTP file upload. should it be done by dedicating each user a FTP account to let them upload files using FTP clients such as FileZilla ? if so , how incoming processes should be handled . for example I give each user a directory like /home/user1 and he uploads his files into this directory. Now how should I fetch uploaded file data and save it to database according to user session data.
Generally , I mean how to script over this FTP file uploading system?
or if it is impossible please tell me.

please help.

pause/resume is not a standard feature of HTTP uploads.

It ought to be possible to get it working, but only with a lot of work, and probably quite flaky quality.

To implement resuming, you'd need the following:

  • a Javascript front end that can query the server and ask how much of the file was already uploaded.
  • the Javascript would also need to be able to break up the upload file into chunks in the browser (this is going to be very painful for the user with a 2GB file), and upload it starting at the point the upload stopped previously.
  • since the HTTP request sends the whole file in one go, if you want to be able to pause, the Javascript would also need to send it in chunks, and have an event handler that aborts the next chunk if the user presses 'cancel'.
  • your PHP program would treat each resume as a whole new file upload, so it would need to know that it's receiving a new chunk of an existing file, and use append mode.

If that sounds like a recipe for a flaky and error-ridden system, then you'd be right. I wouldn't want to use a site like this to upload a file. There's just too many things that can go wrong.

There's a tutorial here that may help, but I still don't think it's a good idea.

If I were you, I'd consider setting up an (S)FTP server for your uploads. It will be a lot less hassle.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM