I have been testing the following code on my site from the question: LAMP: How to create .Zip of large files for the user on the fly, without disk/CPU thrashing
<?php
// make sure to send all headers first
// Content-Type is the most important one (probably)
//
header('Content-Type: application/octet-stream');
header('Content-disposition: attachment; filename="file.zip"');
// use popen to execute a unix command pipeline
// and grab the stdout as a php stream
// (you can use proc_open instead if you need to
// control the input of the pipeline too)
//
$fp = popen('zip -0 -r - file1 file2 file3', 'r');
// pick a bufsize that makes you happy (8192 has been suggested).
$bufsize = 8192;
$buff = '';
while( !feof($fp) ) {
$buff = fread($fp, $bufsize);
echo $buff;
flush();
}
pclose($fp);
It works well to stream the zipping on the fly.
But there is a problem that it does not send the file size to the user. Presumably because its sends the data as its zipping on the fly.
Since I am using zero compression zipping, is there any way to have it send the size to the user since the size is known? Thanks