简体   繁体   中英

Laravel response download does not download zip file and show no errros

I am trying to download an existing zip file. response()->download as explained in HTTP Responses - Laravel does not start a download and show no errors.

Tried several combinations: with name, without name, with different headers, without headers, different folders and also with Response::download instead of response()->download.

In all of them the download doesn't start and I have no errors.

$filename = 'test.zip';
$zip_file_path = storage_path("app/uploads/public/temp/{$filename}");
$headers = ["Content-Type" => "application/zip"];

return response()->download($zip_file_path, 'test.zip', $headers);

The file exists and if the path is not valid, I get the normal "file does not exist" error.

The extension=php_fileinfo.dll is uncommented.

Can you help me with more ideas? I really wanted to use this function in order to use the deleteFileAfterSend(true) feature.

Thank you

The problem was that I was using ajax to call this function. Ajax calls cannot return streams!

So the solution was, after this ajax call, redirect to a new controller's method that returns the response()->download :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM