我使用PHP脚本下载文件,当你去一个页面,但我不能设置它,所以当一个人下载文件,它会显示文件大小(我的显示"未知时间剩余")。我在谷歌上找了一下,找不到如何让文件大小显示出来,因为根据所有这些脚本,我做得对。我已经回显了文件大小,以确保脚本正确读取文件,并以字节为单位返回正确的文件大小。
$file = 'audio/song.mp3';
if(file_exists($file)) {
header('Content-description: File Transfer');
header('Content-type: application/force-download');
header('Content-disposition: attachment; filename="' . $songname . '_' . $filetype . '.' . $ext . '"');
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
ob_clean();
flush();
readfile($file);
exit;
}
else {
die;
}
提前感谢。
谢谢你,禁用mod_deflate成功了。
如果有人在这里绊倒,需要找出如何修复它,将此添加到您的。htaccess。
# for URL paths that begin with "/foo/bar/"
SetEnvIf Request_URI ^/foo/bar/ no-gzip=1
# for files that end with ".py"
<FilesMatch '.py$>
SetEnv no-gzip 1
</FilesMatch>
我了解到Apache的"mod_deflate"扩展可能会导致这种类型的脚本出现问题。如果您启用了它,您应该为特定的脚本禁用它。