繁体   English   中英

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

[英]File size will not display on PHP download script during file download

当你去一个页面时,我正在使用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”扩展可能会导致此类脚本出现问题。 如果已启用它,则应为该特定脚本禁用它。

暂无
暂无

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

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