2015-08-20 134 views
0

我的PHP腳本強制一個文件下載,這一切都正常,但是當強制zip文件下載時,它們會損壞。在PHP中強制文件下載損壞zip文件

當我嘗試打開壓縮文件在本地,它只是從.zip轉換爲.zip.cpgz

如果我下載一個直接URL中的zip文件是罰款的文件,所以我知道它的推動過程中只有墮落/下載階段。

這裏是我的代碼

header("Content-Type: application/octet-stream"); 
    header("Content-Disposition: attachment; filename=\"_zip_download.zip\""); 
    header("Content-Transfer-Encoding: Binary"); 
    header("Content-Description: File Transfer"); 
    header("Content-Length: " . filesize($zip_file)); 
+1

可能重複[如何強制與PHP文件下載(http://stackoverflow.com/questions/ 7263923/how-to-force-file-download-with-php) – e4c5

回答

1

對於壓縮文件,您可以設置的header("Content-Type: application/zip");

header("Content-Type: application/zip"); 
header("Content-Disposition: attachment; filename=\"_zip_download.zip\""); 
header("Content-Length: " . filesize($zip_file)); 
readfile($zip_file); 
exit; 
+0

不幸的是,這並沒有什麼區別。 –

+0

你使用'readfile'功能嗎?你能否嘗試在不同的瀏覽器下載文件? –

+1

我設法解決了這個問題。這是在文件之前發送標題的問題。 –