简体   繁体   English

Firefox将下载retrieve.php,而不是每个Content-Disposition标头指定的文件名

[英]Firefox downloads retrieve.php instead of filename given per Content-Disposition header

I have a PHP script called retrieve.php that compresses uploaded files from a directory in to a .zip file and then outputs them to the stream, so said file can be downloaded. 我有一个名为retrieve.php的PHP脚本,该脚本将目录中的已上传文件压缩为.zip文件,然后将它们输出到流中,因此可以下载所述文件。

The script works in all browsers except Firefox. 该脚本可在除Firefox之外的所有浏览器中使用。 After searching online for quite a while now and coming across this question: PHP download script returns download-file.php instead of filename and still having the same issue, I'm stumped and have no clue what's going wrong. 在网上搜索了一段时间之后,遇到了这个问题: PHP下载脚本返回的是download-file.php而不是filename,并且仍然存在相同的问题,我很困惑,不知道出了什么问题。

This is the code being used to download the file: 这是用于下载文件的代码:

if ($zippedElements >= 1) {
//      die($zipFilename);
        $zipFilename = "download-".time().".zip";
        // Send zip to recipient
        header("Content-Dispositon: attachment; filename=\"$zipFilename\"");
        header("Content-Length: ".filesize($zipFileName));
        header("Content-Type: application/zip");
        header("Content-Transfer-Encoding: binary");
        header("Connection: Keep-Alive");
        header("Expires: 0");
        header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
        header("Pragma: public");
        header("Accept-Ranges: bytes");
        readfile($zipFileName);

    } else return;

I've tried setting the header to different values, such as content-type: application/force-download, adding the asterisk (*) after filename, etc., but all to no avail. 我尝试将标头设置为不同的值,例如content-type:application / force-download,在文件名后添加星号(*),等等,但都无济于事。

The result in Firefox looks as follows: Firefox中的结果如下所示:

在此处输入图片说明

Any help with the matter would be much appreciated. 对此事的任何帮助将不胜感激。

You have inconsistencies in the variable name $zipFilename - the N is uppercased sometimes. 变量名$ zipFilename中存在不一致的地方-N有时是大写的。

    $zipFilename = __FILE__;
    // Send zip to recipient
    header("Content-Dispositon: attachment; filename=\"$zipFilename\"");
    header("Content-Length: ".filesize($zipFilename));
    header("Content-Type: application/zip");
    header("Content-Transfer-Encoding: binary");
    header("Connection: Keep-Alive");
    header("Expires: 0");
    header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
    header("Pragma: public");
    header("Accept-Ranges: bytes");
    readfile($zipFilename);

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

相关问题 PHP Content-Disposition header:文件名中的特殊字符 - PHP Content-Disposition header: Specialcharacters in the filename php标头内容处置 - php header Content-disposition 如何更正Content-Disposition标头中的文件名值? - How to correct filename value in Content-Disposition header? 使用 PHP 中的“content-disposition:attachment”标头获取请求的内容 - Get content of a request with 'content-disposition: attachment' header in Php PHP标头内容 - 处置:附件强制.php文件或内联 - PHP Header Content-Disposition: attachment forces .php file or inline 标头(“ Content-Type:应用程序/ zip”)和标头(“ Content-Disposition:附件;文件名= $ fileName”)在wordpress中不起作用? - header(“Content-Type: application/zip”) and header(“Content-Disposition: attachment; filename=$fileName”) not working in wordpress? PHP标题:内容处理:附件,然后位置:一些网址 - PHP Header : Content-disposition: attachment , then Location: some url 使用Apache mod_header的动态文件名和使用Content-Disposition的文件下载 - Dynamic file names with Apache mod_header and file downloads using Content-Disposition 从URL检索zip,但使用Content-Disposition文件名标识符保存到本地文件 - Retrieve zip from URL, but save with Content-Disposition filename identifier to local file 客户端缺少内容处理标头 - Content-Disposition header missing at client
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM