2015-05-06 283 views
0

我試圖使用它來下載一個.tgz文件複製到以下幾點:PHP下載文件損壞

$file = '/var/www/upload/myfile.tgz'; 

if (file_exists($file)) 
{ 
    header('Content-Description: File Transfer'); 
    header('Content-Type: application/octet-stream'); 
    header('Content-Disposition: attachment; filename='.basename($file)); 
    header('Expires: 0'); 
    header('Cache-Control: must-revalidate'); 
    header('Pragma: public'); 
    header('Content-Length: ' . filesize($file)); 
    readfile($file); 
    exit; 
} 

的問題是,當我試圖解壓下載的文件 與tar使我有以下錯誤:

gzip: stdin: not in gzip format 
tar: Child returned status 1 
tar: Error is not recoverable: exiting now 

注意:嘗試提取原始文件時不會發生此錯誤。

+0

存檔是tar而不是GZip存檔。 –

+0

解壓焦油沒有Z,它是gzip壓縮(壓縮),僅: –

+2

http://stackoverflow.com/questions/15744023/how-to-extract-filename-tar-gz-file – Saty

回答

0

當我將代碼移動到一個單獨的.php文件時它工作

+0

似乎比在舊的PHP文件你呼應了一些字符,例如空白處在頭部或開頭前的空白處並退出呼叫。 – take