Download large file in php
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. Ben sorry for that. You may download it from Github directly: github. PrettyCoder PrettyCoder. I had to fix a couple deprecated reference errors and non-static method usage, but in 5 minutes i got it up and running, so it's nothing too hard.
It may be because i have an outdated pear library, but it's worth to notice. This didn't age very well. Andreas Baumgart Andreas Baumgart 2, 1 1 gold badge 23 23 silver badges 19 19 bronze badges. I attempted this, but all it seemed to do was output text to the screen. How do I turn this into a file to download? This is a different topic. Wouldn't 4KB chunks be inefficient? I would at least do 0.
As part generating these links you could also remove files that were more than X hours old. Andrew Grant Andrew Grant I don't like this answer because it requires additional use of crons or such to remove the old files, and that adds another layer of complexity and another point of failure to the system, but I'm not going to vote it down because it is a valid answer.
Unkwntech - no need for cron, as mentioned while generating new files you can also discard older ones. Lots of websites perform cron-like tasks as part of another call.
Andrew Grant, you are correct that it could be done without a CRON, but I still feel that it adds an extra point of failure, whereas with my answer I don't think that it is adding an extra failure point. But what you get out of it is punting the complexity of the actual HTTP communication to the server, where it belongs things like expire headers, range downloads, caching, etc.
I would rather clean up a few files with a script than reimplement HTTP in my application. I agree with Will. Browsers these days have sophisticated downloaders that can pause and resume downloads using built-in features of http. You can then setup a CRON job to delete the symbolic links at regular intervals Hummdis Hummdis 57 5 5 bronze badges.
UnkwnTech UnkwnTech Of course, if this isn't an exe, the mime type should be different. Very true, unless of course you want the script to continue running after the user dies. That would leave evidence that you killed the user. Not exactly a good idea. Down vote.
Show 4 more comments. Community Bot 1 1 1 silver badge. Will not work for large files. Would run out of memory within seconds. Scottymeuk Why? Please provide a resource. Instantly share code, notes, and snippets. Created Oct 3, Code Revisions 2 Stars 28 Forks 6. Embed What would you like to do? 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. Dont work for large files, i got "Maximum execution time of 30 seconds exceeded". Thank you very much!
0コメント