Php stream file to browser
I have a 200MB file that I want to give to a user via download. However, since we want the user to only download this file once, we are doing this:
to force a download. However, this means that the whole file has to be loaded in memory, which usually doesn't work. How can we stream this file to them, at some kb per chunk?
animuson♦ 52.6k28 gold badges139 silver badges145 bronze badges asked Aug 2, 2011 at 15:56
Filo StacksFilo Stacks 1,9212 gold badges20 silver badges20 bronze badges 1 Try something like this (source http://teddy.fr/2007/11/28/how-serve-big-files-through-php/):
answered Aug 2, 2011 at 16:01
diagonalbatmandiagonalbatman 17k3 gold badges29 silver badges31 bronze badges 3 Use Modified from the example in the manual:
If you would rather stream the content directly to the browser rather than a download (and if the content type is supported by the browser, such as video, audio, pdf etc) then remove the Content-Disposition header.
answered Nov 6, 2014 at 16:43
5 Take a look at the example from the manual page of
This will connect to answered Aug 2, 2011 at 16:01
ridrid 58.5k30 gold badges145 silver badges189 bronze badges 2 I found this method in http://codesamplez.com/programming/php-html5-video-streaming-tutorial And it works very well for me
To use this class, you will have to write simple code like as below:
answered Oct 6, 2016 at 13:52
0 I ran into this problem as well using readfile() to force a download. The memory problem lies not within readfile, rather with ouput buffering. Just make sure you switch off output buffering before readfile, and the problem should be fixed.
Works for files with a size much larger than the allocated memory limit. answered Mar 25, 2020 at 14:05
GillyGilly 8,8345 gold badges31 silver badges33 bronze badges 1 Not the answer you're looking for? Browse other questions tagged php download or ask your own question. |