gpt4 book ai didi

php - 文件下载期间,文件大小不会显示在 PHP 下载脚本中

转载 作者:搜寻专家 更新时间:2023-10-31 21:17:30 27 4
gpt4 key购买 nike

当您转到某个页面时,我正在使用 PHP 脚本下载文件,但我无法将其设置为当有人下载​​该文件时,它会显示文件大小(我的显示“未知剩余时间” ”)。我在 Google 上环顾四周,找不到如何让文件大小显示给我的信息,因为根据所有这些脚本,我做对了。我已回显文件大小以确保脚本正确读取文件,并返回正确的文件大小(以字节为单位)。

$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”扩展可能会导致此类脚本出现问题。如果您启用了它,您应该为该特定脚本禁用它。

关于php - 文件下载期间,文件大小不会显示在 PHP 下载脚本中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5547471/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com