簡體   English   中英

Firefox將下載retrieve.php,而不是每個Content-Disposition標頭指定的文件名

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

我有一個名為retrieve.php的PHP腳本,該腳本將目錄中的已上傳文件壓縮為.zip文件,然后將它們輸出到流中,因此可以下載所述文件。

該腳本可在除Firefox之外的所有瀏覽器中使用。 在網上搜索了一段時間之后,遇到了這個問題: PHP下載腳本返回的是download-file.php而不是filename,並且仍然存在相同的問題,我很困惑,不知道出了什么問題。

這是用於下載文件的代碼:

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;

我嘗試將標頭設置為不同的值,例如content-type:application / force-download,在文件名后添加星號(*),等等,但都無濟於事。

Firefox中的結果如下所示:

在此處輸入圖片說明

對此事的任何幫助將不勝感激。

變量名$ 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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM