繁体   English   中英

查看此php下载脚本的下载进度吗?

[英]See download progress with this php download script?

我正在使用此脚本下载文件,并且可以正常工作,但是在浏览器中没有获得%或时间的下载进度,只是说未知。 是否可以调整代码以添加该参数? 除此之外,你们是否在代码中看到其他任何奇怪的东西或可以改进的东西? 谢谢!

<?php

$filepath = 'x';
$title = 'y';
$download = true;

header("Cache-control: private");

header("Content-Type: application/octet-stream");

if ($download) {
       header("Content-Disposition: attachment; filename=\"" . $title . "\"");
       header('Content-Transfer-Encoding: binary');
} else {
       header("Content-Disposition: inline; filename=\"" . $title . "\"");
}

// Disable caching
header('Cache-Control: no-cache, no-store, must-revalidate'); // HTTP 1.1.
header('Pragma: no-cache'); // HTTP 1.0.
header('Expires: 0'); // Proxies.

readfile($filepath);

exit;

?>

服务器未发送Content-Length标头,因此客户端无法知道还需要多少数据,因此无法显示进度。 如果响应包含文件的内容,则可以通过调用stat( $filepath )获得文件大小。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM