PHP ZIP file download

后端 未结 7 1223
一生所求
一生所求 2020-12-17 05:51

Here is a code which downloads attachment files from the an imap server. Almost all file types (pdf, doc, xls, etc) are being downloaded correctly, where as some zip files g

7条回答
  •  隐瞒了意图╮
    2020-12-17 06:20

    This is really good for big file download. User will be receiving file immediately. Maybe zip will be correct too this way.

        if(file_exists($filename) && is_readable($filename) && file_exists($filename)){
                 header("Content-Disposition: attachment; filename=".basename(str_replace(' ', '_', $filename)));
                 header("Content-Type: application/force-download");
                 header("Content-Type: application/octet-stream");
                 header("Content-Type: application/download");
                 header("Content-Description: File Transfer");
                 header("Content-Length: " . filesize($filename));
                 flush(); // this doesn't really matter.
    
                 $fp = fopen($filename, "r");
                 while (!feof($fp))
                 {
                     echo fread($fp, 65536);
                     flush(); // this is essential for large downloads
                 }
                 fclose($fp);
             exit;
        }
    

提交回复
热议问题