标头问题,使zip无法下载和创建

时间:2019-04-09 12:43:32

标签: php header zip

使zip文件无法创建和下载时显示仅zip名称的问题

if (file_exists($filename)) {
    header("HTTP/1.1 200 OK");
    header("Pragma: public");
    header("Cache-Control: must-revalidate, post-check=0, pre-check=0");

    header("Cache-Control: private", false);
    $mimeType = 'application/json';
    header("Content-type: " . $mimeType);

    header("Content-Disposition: attachment; filename=\"{$filename}\""); 

    header("Content-Transfer-Encoding: binary");
    header("Content-Length: " . mb_strlen($filename));
    echo $filename;

    flush();
    readfile($filename);
    // delete file
    unlink($filename);
}

1 个答案:

答案 0 :(得分:0)

尝试这样设置Content-type:header("Content-type: application/zip");