2017-04-21 161 views
0

我正在使用下面的代碼下載壓縮文件。我確定該文件已存在並正在服務器上運行。提取後的結果是.cpgz文件。解壓縮後下載zip文件導致.cpgz文件

return response()->download('/Applications/XAMPP/xamppfiles/htdocs/stoproject/source/storage/app/Copy of StoTherm Classic®.zip'); 

該代碼正在工作,沒有任何改變,停止。

我也嘗試添加標題:

$headers = array(
      'Content-Type' => 'application/zip', 
     ); 

return response()->download('/Applications/XAMPP/xamppfiles/htdocs/stoproject/source/storage/app/Copy of StoTherm Classic®.zip', basename('/Applications/XAMPP/xamppfiles/htdocs/stoproject/source/storage/app/Copy of StoTherm Classic®.zip'), $headers); 

還與嘗試:

'Content-Type' => 'application/octet-stream' 

回答

0

調用ob_end_clean()固定問題

$response = response()->download($pathToFile)->deleteFileAfterSend(true); 

ob_end_clean(); 

return $response; 

Laravel 4 Response download issue