How to upload large files using php




















Fortunately, we can increase the limit when necessary. However, you also need to consider the time it takes to complete an upload. PHP scripts normally time-out after 30 seconds, but a 10MB file would take at least 3 minutes to upload on a healthy broadband connection remember that upload speeds are typically five times slower than download speeds.

Also, HTTP is so not meant for this Is there no way to achieve this in PHP? Thanatos: Yeah I can see the variables in phpinfo and they are correct. Show 5 more comments. Active Oldest Votes. The error was very same: PHP Warning: POST Content-Length of bytes exceeds the limit of bytes in Unknown on line 0 I spent a day wondering where the heck was this "limit of " coming from!

Solution : Actually, the error was in the php. Changing the value to e. Community Bot 1 1 1 silver badge. Mobiler Mobiler 3 3 silver badges 10 10 bronze badges. I've been hours trying to find out what could be the issue with a owncloud install for uploading big files, and this was the issue after all.

This answer just solved what I spent days trying to solve! I wish I could give this more upvotes — Eric F. Add a comment. That's what I did because Go Daddy kills the script from running after 2 minutes 30 seconds or so This whole process will then send the file to the browser and it doesn't matter how long it runs since it's not a script. These 3 lines of code will do all the work of the download readfile will stream the entire file specified to the client, and be sure to set an infinite time limit else you may be running out of time before the file is finished streaming.

If you are using lighttpd as a webserver, an alternative for secure downloads would be to use ModSecDownload. It needs server configuration but you'll let the webserver handle the download itself instead of the PHP script. Generating the download URL would look like that taken from the documentation and it could of course be only generated for authorized users:. Of course, depending on the size of the files, using readfile such as proposed by Unkwntech is excellent.

And using xsendfile as proposed by garrow is another good idea also supported by Apache. I'm not sure this is a good idea for large files. If the thread for your download script runs until the user has finished the download, and you're running something like Apache, just 50 or more concurrent downloads could crash your server, because Apache isn't designed to run large numbers of long-running threads at the same time. Of course I might be wrong, if the apache thread somehow terminates and the download sits in a buffer somewhere whilst the download progresses.

Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams? Collectives on Stack Overflow. Learn more. Asked 12 years, 10 months ago. Active 4 months ago. Viewed 50k times. What is the best way to solve this problem?

Regards erwing. Erwing Erwing 1 1 gold badge 3 3 silver badges 4 4 bronze badges. Part of this problem might be solved by supporting Range headers, so browsers can pause and resume downloads. Here's a question dealing with that: stackoverflow. Also take a look at this and this SO answers. See it here -- stackoverflow. Add a comment. Active Oldest Votes.

This is a prefectly working solution, used and tested in many of my projects. Pity in both cases Tell me, where, exactly where in readfile doc you see any mention about chunking?

Check, before you state your false claims! The upload is aborted and you need to start from the beginning. Even worse, if you are in a slow connection, like many places in the world, no matter how often you try you will only be able to upload first part of the upload every time. In this post, we will see an attempt to solve this problem in PHP by uploading files in resumable chunks using tus protocol. Tus is a HTTP based open protocol for resumable file uploads. Resumable means we can carry on where we left off without re-uploading whole data again in case of any interruptions.

An interruption may happen willingly if the user wants to pause, or by accident in case of a network issue or server outage. Another main benefit of uploading a file this way is that you can start uploading from a laptop and even continue uploading the same file from your mobile or any other device. This is a great way to enhance your user experience. You need to configure your server to respond to a specific endpoint.

For example, in Nginx, you would do something like this:.



0コメント

  • 1000 / 1000