PHP Download Script Creates Unreadable ZIP File on Mac

前端 未结 3 595
青春惊慌失措
青春惊慌失措 2021-01-07 13:53

For reference, I have already read and tried the answers in these and several other threads:

Creating and serving zipped files with php

Opening downloaded zi

3条回答
  •  自闭症患者
    2021-01-07 14:06

    Here is what works

    $zipName = 'myfile.zip';
    $zipPath = 'mydirectory/' . $zipName;
    
        if (file_exists($zipPath)) {
    
            header("Pragma: public");
            header("Expires: 0");
            header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
            header("Cache-Control: public");
            header("Content-Description: File Transfer");
            header("Content-type: application/octet-stream");
            header("Content-Disposition: attachment; filename=\"".$zipName."\"");
            header("Content-Transfer-Encoding: binary");
            header("Content-Length: ".filesize($zipPath));
            ob_end_flush();
            @readfile($zipPath);
    }
    

提交回复
热议问题