[英]How to enable download progress bar in a web browser during file download in PHP script?
I have the following PHP script that outputs a file for download to an end-user: 我有以下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);
}
The user can download the file just fine, but when a large file is being downloaded the web browser doesn't show a progress bar with the percentage of the file remaining to download. 用户可以很好地下载文件,但是当下载大文件时,Web浏览器不会显示进度条以及剩余的文件下载百分比。 It only displays the number of MB currently downloaded. 它仅显示当前下载的MB数。
So I'm curious, what shall I change in the header to enable this download progress? 所以我很好奇,我应该在标题中进行哪些更改以启用此下载进度?
PS. PS。 Here's a screenshot: 这是屏幕截图:
假设它是gzip,并且与不知道实际的内容长度有关……也许添加此标头?
header("accept-encoding: gzip;q=0,deflate;q=0");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.