我正在使用以下代码下载一个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 :(得分:1)
调用ob_end_clean()修复了问题
$response = response()->download($pathToFile)->deleteFileAfterSend(true);
ob_end_clean();
return $response;