我在PHP中创建了一个文件下载脚本,它工作正常,但是网页浏览器将文件报告为“未知长度”。我的代码如下:用PHP下载脚本发送正确的文件大小
function downloadFile($file){
// Set up the download system...
header('Content-Description: File Transfer');
header('Content-Type: '.mime_content_type($file));
header('Content-Disposition: attachment; filename="'.basename($file).'"');
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: '.filesize($file));
// Flush the cache
ob_clean();
flush();
// Send file to browser
readfile($file);
// DO NOT DO ANYTHING AFTER FILE DOWNLOAD
exit;
}
有趣。我需要研究一下。 – 2010-03-12 17:13:34
谢谢,我在下载时收到了“gzip”内容类型,并且能够通过htaccess线删除它,现在我可以再次看到下载进度,因为浏览器正确读取了文件总大小。 – adrianTNT 2014-10-23 19:36:17