Saeed
Saeed

Reputation: 3520

Return images from storage folder

I have some images in the storage folder. I want to get them in response and show to my users.

What I try:

I use the following code but it returns NULL:

// All images are in the storage/app/users/{id}/document folder
$path = storage_path( 'app/users/'.$id . '/document');
if (!File::exists($path)) {
    abort(404);
} 
$file = File::files($path);
$type = File::mimeType($path);
$response = Response::make($file, 200);
$response->header("Content-Type", $type);
return $response;

Output: Null

Upvotes: 0

Views: 88

Answers (1)

Farshad Fahimi
Farshad Fahimi

Reputation: 648

By the laravel documentation

you can resolve this.

return Storage::files('users/'.$id .'/document')

the default path of store file in laravel is storage/app/public and by default you should not set this path and your path is after this and laravel by default start from this path

and remember to add use Illuminate\Support\Facades\Storage; in top of your class

Upvotes: 1

Related Questions