Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

t0berius's avatar

response download with file from storage

How can I response with a download in laravel using the result of

$file = Storage::disk('local')->get('image.jpg');

as downloadable file? The get() returns the file in raw, but using

return response()->download($pathToFile, $name, $headers);

just accepts a path to file. Because I would like to work with local and cloud storage I need to find a way to retrieve files from cloud storage and return them as download to the user. Any idea?

0 likes
5 replies
pmall's avatar

I know it is a problem but there is no other solution than putting the path of the file. So when the file is uploaded you have to store the path of the file.

t0berius's avatar

:/ Ohh that's very bad. Any idea why the path doesn't work? my local storage config:

'local' => [
        'driver' => 'local',
        'root'   => storage_path('app/uploads'),
    ],

I use this in controller:

        return response()->download(storage_path() . $ticket_reply->file->name);

results in

The file "C:\xampp\htdocs\projekt\storageasasass-1453144780.jpg" does not exist

the filename is correct. What's wrong, seems like laravel ignores my config completly.

1 like
pmall's avatar

The root of your disk is storage_path('app/uploads'), so you have to put storage_path('app/uploads') instead of storage_path() in your response()->download() call.

1 like
TerrePorter's avatar

This will return the full path to the requested file,

 Storage::disk($disk)->getDriver()->getAdapter()->applyPathPrefix($file)
8 likes
codymoorhouse's avatar

Thanks TerrePorter!

That is exactly what I was looking for! (I Realize you posted this a year ago)

Please or to participate in this conversation.