I created a file download script in PHP, it works, but web browsers report the file as "Unknown Length". My code is as follows:
// Set up the download system...
header('Content-Description: File Transfer');
header('Content-Disposition: attachment; filename="'.basename($file).'"');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
// Flush the cache
// Send file to browser
// DO NOT DO ANYTHING AFTER FILE DOWNLOAD
Originally from http://paul.luminos.nl/update/471:
Andrew makes a very important comment at the end of the article:
"If you compress files with Zlib, mod_deflate and so on the Content-Length header won't be accurate so you'll end up seeing "Unknown size" and "Unknown time remaining" when downloading files."
I would like to stress this: if your browser doesn't appear to be obeying the headers generated by your PHP script—especially
Content-Length—it is fairly likely that Apache's
mod_deflateextension is enabled.
You can easily disable it for a single script using the following line in an applicable
SetEnvIfNoCase Request_URI ^/download\.php no-gzip dont-vary
where download.php is here assumed to be in the download script located in the server's root directory path (e.g.
www.crimsonbase.com/download.php). (That's because the regular expression is