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

Kris01's avatar

Laravel Download FIle from storage

Hi,

            return Storage::download($file['path'], $file['name']);

I am using this way to download some files I have in the storage but it's throwing

Unable to retrieve the file_size for file at location: nameofthefile.pdf

0 likes
11 replies
Sinnbeck's avatar

What does this give you?

dd(Storage::exists($file['path']));
1 like
Sinnbeck's avatar

@Kris01 you need to provide it the proper path (or disk)

Is this better? If not you need to tell me what $file['path']is

dd(Storage::disk('public')->exists($file['path'])); 
Kris01's avatar

@Sinnbeck File['path'] is actually the file name, which is stored in storage/app/public/files

Sinnbeck's avatar

@Kris01 ok so how about

dd(Storage::disk('public')->exists('files/'. $file['path']));  
1 like
Sinnbeck's avatar
Sinnbeck
Best Answer
Level 102

@Kris01 like this

return Storage::disk('public')->download('files/'. $file['path'], $file['name']);
2 likes
Kris01's avatar

@Sinnbeck It works, but I don't know why when I put a custom name, it doesn't download it as pdf, but as something else, just file

Kris01's avatar

@Sinnbeck My bad, I was not adding .pdf, yes the file name was just 'filename'.

got it thank you

eugenefvdm's avatar

Thank goodness this search comes up high in Google. What throws one off is the file_size bit but it's actually just a file not found problem. In my case I'm was using Barryvdh/DomPDF facade and naively thought this line would happily find it in the right place when I download:

$pdf->save(storage_path() . "/invoice_$invoice->id.pdf");

In fact I had to go over the paths with a magnifying glass before I could figure it out. This line from @sinnbeck was the big clue:

dd(Storage::exists($file['path']));
2 likes

Please or to participate in this conversation.