我使用下面的代码强制浏览器开始下载:
//send file
$fileName = basename($fullPath);
$length = filesize($fullPath);
header('Content-Type: application/octet-stream');
header("Content-Transfer-Encoding: Binary");
header('Content-length: ' . $length);
header("Content-disposition: attachment; filename=$fileName");
readfile($fullPath);
exit;
一切正常,除了浏览器(Firefox 和 Chrome)中未显示总文件大小。我搜索了社区并在 htaccess 中测试了以下代码,但没有成功:
SetEnv no-gzip 不要变化
SetEnvIfNoCase Request_URI ...
我的网络服务器是 Apache,PHP 版本为 8.3
还有其他选项可以检查吗?
最近我也遇到了同样的问题!建议也添加此标头而不是 htaccess 解决方案
//to show file-size in browser
header("Content-Encoding: none");