Zip 文件下载,但无效?

Ale*_*nch 1 php download

我使用此代码使用户能够下载 zip 文件:

if(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();

         $fp = fopen($filename, "r");
         while (!feof($fp))
         {
             echo fread($fp, 65536);
             flush();
         }
         fclose($fp);
     exit;
}
Run Code Online (Sandbox Code Playgroud)

下载文件时,它仅下载 25,632 KB 的数据。但是 zip 文件是 26,252 KB ...

为什么浏览器获得了所有 25MB 然后停止?

我检查了Content-Length标题以确保它是正确的,它是...

编辑

在firefox中,当我下载文件时,它说“25mb”所以浏览器认为25mb是完整的数量……但是,echo'd时的内容长度是26252904?

Shu*_*man 6

在你的代码之前添加这个

ob_clean();
ob_end_flush();
Run Code Online (Sandbox Code Playgroud)