5

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?

Marcin Nabiałek
  • 109,655
  • 42
  • 258
  • 291
Alex
  • 485
  • 6
  • 18

1 Answers1

1

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);
Marcin Nabiałek
  • 109,655
  • 42
  • 258
  • 291