我有以下PHP脚本,它输出一个文件供下载给最终用户:
session_write_close();
ob_end_clean();
set_time_limit(0);
if($file = fopen($path, 'rb'))
{
header("Cache-Control: no-cache");
header("Pragma: no-cache");
header("Accept-Ranges: bytes");
header("Content-length: ".(string)(filesize($path)));
header("Content-Disposition: attachment; filename=\"".basename($path)."\"");
header("Content-type: application/octet-stream");
header("Content-Transfer-Encoding: binary");
header("Connection: close");
fpassthru($file);
fclose($file);
}
用户可以正常下载文件,但是当下载大文件时,Web浏览器不显示进度条,其中包含要下载的文件的剩余百分比。它仅显示当前下载的MB数。
所以我很好奇,我应该在标题中更改什么才能启用此下载进度?
PS。这是一个截图:
答案 0 :(得分:0)
假设它是gzip并且与不知道实际内容长度有关...可能会添加此标题?
header("accept-encoding: gzip;q=0,deflate;q=0");