Download large file php






















Take a look at the example from the manual page of fsockopen :. This will connect to www. You may want to make it more than bytes. I ran into this problem as well using readfile to force a download. The memory problem lies not within readfile, rather with ouput buffering. 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 10 years, 3 months ago. Active 1 year, 8 months ago. Viewed k times. Improve this question. Filo Stacks Filo Stacks 1, 2 2 gold badges 19 19 silver badges 20 20 bronze badges. Add a comment. Active Oldest Votes. Improve this answer. Edson Horacio Junior 2, 2 2 gold badges 23 23 silver badges 44 44 bronze badges.

Can the chunks be gzipped too? This prevents download. As the file handle closes by itself in my case, I have omitted this and everything works fine. 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, 9 months ago. Active 2 months ago. Viewed 50k times. What is the best way to solve this problem? Regards erwing. Improve this question. 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. Improve this answer. 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! From the documentation: "Note: readfile will not present any memory issues, even when sending large files, on its own. GellieAnn You're referring to 7 years old answer.

I am no longer PHP developer. But I cannot verify that in practice. Maybe here is the problem. Not about files that you're going to download this way. Downloaded files were meant to be binary. Binary files cannot be encoded with text encoding like UTF Show 6 more comments. PJunior 2, 28 28 silver badges 29 29 bronze badges. Thanks, I didn't know about that one. There is a " large file download " PHP script here that can handle around 2GB of many file types like exe, mp3, mp4, pdf etc.

This script is worth for downloading smaller to medium file sizes via PHP script. It also describes about X-sendfile for really massive file downloads like more than 5GB. Check out the link. Embed Embed this gist in your website. Share Copy sharable link for this gist. Learn more about clone URLs. Download ZIP. Download large file from the web via php. This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below.

To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters Show hidden characters. This comment has been minimized. Sign in to view. Copy link Quote reply.



0コメント

  • 1000 / 1000