php download do not show progress in browser
<p>I have problem with a php managed file download where the browser do no show progress of a file download.  In fact, the browser appears to be waiting and waiting and waiting, until the file is completely downloaded.  The file will then appear in the download list (with chrome and firefox).  I cannot even download the file with IE8.  I would like the browser to show the actual file size and the progress of the download.</p>

<p>Strangely the download is not even visible in firebug (no line appear in the network tab if you paste the download url).</p>

<p>I suspected problem with compression/zlib so I disabled both: no change.  I disabled output buffering with the same result.</p>

<p>Live example can be found here: <a href="http://vps-1108994-11856.manage.myhosting.com/download.php" rel="nofollow">http://vps-1108994-11856.manage.myhosting.com/download.php</a>
Phpinfo: <a href="http://vps-1108994-11856.manage.myhosting.com/phpinfo.php" rel="nofollow">http://vps-1108994-11856.manage.myhosting.com/phpinfo.php</a></p>

<p>The code is below, your help is appreciated.</p>

<pre><code>&lt;?php

$name = "bac.epub";
$publicname = "bac.epub";

@apache_setenv('no-gzip', 1);
ini_set("zlib.output_compression", "Off");

header("Content-Type: application/epub+zip");
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Transfer-Encoding: binary");
header("Content-Length: " . filesize($name));
header("Content-disposition: attachment; filename=" . $publicname) );
ob_end_flush();
flush();
// dump the file and stop the script
$chunksize = 1 * (128 * 1024); // how many bytes per chunk
$size = filesize($name);
if ($size &gt; $chunksize) {
  $handle = fopen($name, 'rb');
  $buffer = '';
  while (!feof($handle)) {
    $buffer = fread($handle, $chunksize);
    echo $buffer;
    ob_flush();
    flush();
    sleep(1);
  }
  fclose($handle);
} else {
  readfile($name);
}
exit;
</code></pre>

<p>The sleep in the code was to ensure that the download is long enough to see the progress.</p>
