Download doesn't have a progress bar. How to fix?
Posted: Fri Sep 03, 2010 5:16 am
I need to dynamically generate the contents of a file before it's downloaded. I use the following PHP code:
The code above works but when the download starts, IE or FF do not show a progress bar. Why?
Code: Select all
$handle = @fopen($file_path, "rb");
if($handle !== false)
{
//Get file length for output
$length = /*ob_get_length() +*/ filesize($file_path);
//Send contents
header("Pragma: private");
header("Cache-control: private, must-revalidate");
header("Content-Type: application/octet-stream");
header("Content-Transfer-Encoding: Binary");
header("Accept-Ranges: bytes");
header("Content-Length: $length");
header("Content-Disposition: attachment; filename=\"".$outputFile."\"");
header("Connection: close");
$contents = fread($handle, filesize($file_path));
//Change contents in $contents
//Output contents
print $contents;
fclose($handle);
}