2017-04-21 132 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