6.0.0-beta1
▾
Tasks
New Task
Search
Photos
Wiki
▾
Tickets
New Ticket
Search
dev.horde.org
Toggle Alerts Log
Help
11/8/25
H
istory
A
ttachments
C
omment
W
atch
Download
Comment on [#5913] Lower memory usage while downloading files
*
Your Email Address
*
Spam protection
Enter the letters below:
.__..__ .__ .__..___. | |[__)[__)[__] | |__|| | | | |
Comment
> Hi Chuck, > > > > I posted my code in the initial ticket, but just in case you can't > see it for some reason, here it is again (slightly modified to make > it easier to read/use). > > All you'd basically do is call the second function with the filename, > and the file should be send in bits to the browser. > > > > Function ReadFileChunked ($FileName) { > > $chunksize = (102400); // how many bytes per chunk > > $buffer = ''; > > $handle = fopen($FileName, 'rb'); > > if ($handle === false) { return false; } > > while (!feof($handle)) { > > $buffer = fread($handle, $chunksize); > > print $buffer; > > } > > return fclose($handle); > > } > > > > Function SendFileToBrowser ($FileName) { > > Header("Content-Type: application/force-download;"); > > Header("Content-Disposition: attachment; > filename=\"".$FileName."\""); > > Header("Content-Length: ".FileSize($FileName)); > > ReadFileChunked($FileName); > > Exit; > > } > > > >> Btw, you didn't post the code you mentioned yet, but is it really > >> necessary to use chunked reads, or will readfile > >> (http://www.php.net/readfile) or fpassthru do the right thing? In a > >> way fpassthru would be ideal because we can return a stream from the > >> VFS library in some backends, or fake it with a local file. > > > > Did a bit of reading up on fpassthru, and you might want to look at > the first comment on this page: > http://au.php.net/manual/en/function.fpassthru.php. > > There's also various other comments on memory usage downloading files > on that page. > > > > Cheers! Olger.
Attachment
Watch this ticket
N
ew Ticket
M
y Tickets
S
earch
Q
uery Builder
R
eports
Saved Queries
Open Bugs
Bugs waiting for Feedback
Open Bugs in Releases
Open Enhancements
Enhancements waiting for Feedback
Bugs with Patches
Enhancements with Patches
Release Showstoppers
Stalled Tickets
New Tickets
Horde 5 Showstoppers