How to get image file from public folder as a response in Laravel?

Yogesh.galav

These are different ways I have tried in my controller to get image as response.

My images resides in public folder/img.

switch ($document->ext) {

    case 'doc':
        $img = File::get(url('/img/doc.png'));
        break;

    case 'docx':
        $img = File::get(asset('/img/docx.jpg'));
        break;

    case 'pdf':
        $img = File::get(public_path('/img/pdf.png'));
        break;

    case 'ppt':
        $img = File::get(url(public_path('/img/ppt.png')));
        break;

    default:
}
return new Response($img, 200);
Yogesh.galav

I guess it is a better way in case we change the public_path

        case 'doc':
        return response()->file(public_path('img/doc.png'));
        exit;

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to import image into React from public folder through a json file

How to get files list from public folder Laravel

Laravel get public url for file stored in storage public folder

How to call model from public folder in Laravel?

show image stored outside the public folder in view file - Laravel

How to Delete Images from a folder in Public after update of the image in Laravel 8

How can I display pdf file from local public/uploads folder in laravel into html <iframe>

Get image from resources folder - Laravel

Unable to get image from public/images folder in react hooks

How to delete multiple image in public/folder when updating in laravel?

how to save base64 image decode to public folder in laravel

How can I access image in public folder Laravel?

Use an image from public folder

Laravel: How to create a folder in public path dynamically when a file is uploaded?

How to output file above public folder Laravel 5.1

How to get bootstrap-select css into Laravel public folder

How to send back an image in Go from the public folder?

JS - how to importe correctly image from public folder

How i get image from database to view file in laravel

how to display images from public folder in laravel 5.8?

How to preview files from public folder Laravel 5.4

How to redirect to public folder on laravel

How to get file from resource folder as File?

How to get file from storage by public URL?

Laravel Image Upload not saving to public folder

How to import file from public folder in react application?

How to get image from assets by folder ios

How to get and save image to folder from listview

how to get the application folder from the docker image