So i'm using Laravel 5 and I tried to force download a selected file but nothing happens.
public function downloadUserFile(){
$result = $_POST['filename'];
$entry = File::where('filename', $result)->firstOrFail();
$file = Storage::disk()->get($entry->filePath);
$headers = array('Content-Type' => $entry->mimetype);
return response()->download(storage_path($entry->filePath), $result, $headers);
}
and the response headers seem to be ok
Accept-Ranges: none
Cache-Control: public
Connection: Keep-Alive
Content-Disposition: attachment; filename="SIGNAL - Nadezdata.mp3"
Content-Length: 4205059
Content-Type: audio/mpeg
Do you know what's wrong?
I think the problem is in paths.
By default in config/filesystems.php
local path is defined this way: storage_path('app')
and you pass into download the following path: storage_path($entry->filePath)
(no app
included here).
What you should do is changing:
return response()->download(storage_path($entry->filePath), $result, $headers);
into:
return response()->download(storage_path('app/'.$entry->filePath), $result, $headers);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With