[英]How to enable download progress bar in a web browser during file download in PHP script?
我有以下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。 这是屏幕截图:
假设它是gzip,并且与不知道实际的内容长度有关……也许添加此标头?
header("accept-encoding: gzip;q=0,deflate;q=0");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.