2015-07-21 48 views
0

我真的生氣後,花了四個小時沒有結果。我想提供一個zip文件供下載。不通過鏈接,但與readfile(也許有另一種方式?)無論我已經嘗試過,下載後的zip是空的。報價zip在php下載

$file = 'Passiv1.zip'; 
header('Content-Type: application/zip'); 
header('Content-Disposition: attachment; filename="'.$file.'"'); 
header('Content-Length: '.filesize($file)); 
readfile($file); 

任何人都可以幫我嗎?

+0

檢查是否存在Passiv1.zip像 – donald123

+0

@ donald123還要檢查你不需要文件的完整路徑,即,如果它不在運行的php代碼所在的文件夾中 – RiggsFolly

回答

0

對我來說,以下工作:

header("Content-Disposition: attachment; filename=\"".$file."\""); 
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past 

此外,還要確保你沒有其他問題,如Passiv1.zip不可讀取。

嘗試測試與這樣的:

if (is_readable($file)){ 
    echo "OK!"; 
} else { 
    echo "NOT OK!"; 
} 
0

問題解決了:沒有內容應頭前發送,甚至沒有空格