I
I
Ivan2021-09-17 13:22:48
Laravel
Ivan, 2021-09-17 13:22:48

How to submit a file for download in laravel?

Good afternoon. I want to send a file for download, but I still get errors. I do something like this:

$path = 'public/path/to/file/filename.doc';
$storage = Storage::cloud();
$file = $storage->get($path);

return response()->download($file, 'your_file.doc');


At the same time, the error
is_file() expects parameter 1 to be a valid path, string given

I also try through return Response::download($file);, also does not work.
How can I do that?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
pLavrenov, 2021-09-17
@Djonson86

That type.

$path = Storage::disk('local')->path($path);
return response()->download($path, basename($path));

A
Alexey Volodin, 2021-09-17
@alexeyvolodin

Response expects a file path, while Storage returns its contents.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question