user3653474
user3653474

Reputation: 3852

Cannot get image from public folder on Server in Laravel

I'm saving my uploaded image in public folder like

public/user/user_img_1.jpg

and saving

/user/user_img_1.jpg 

in my database column as image path. Now when i get it <img src="{{ $userData->thumb_img }}" alt="Profile Image" /> , the image shows on localhost but on server the image is not found. $userData variables stores the path.

Upvotes: 0

Views: 993

Answers (3)

STA
STA

Reputation: 34828

You have to do any one step :

Put all your files (img) into the public folder.

<img src="/user/{{ $userData->thum_img }}" alt="Profile Image" />

Or, Use asset helper :

<img src="/user/{{ asset($userData->thum_img) }}" alt="Profile Image" />

where user_img_1.jpg is path of your content.

Upvotes: 0

HoratioNullbuilt
HoratioNullbuilt

Reputation: 245

Use asset function to generate a URL for an asset using the current scheme of the request.

In your case that would be: <img src="{{ asset($userData->thumb_img) }} alt="Profile Image" />

Upvotes: 1

Alka Singla
Alka Singla

Reputation: 389

We need to give permissions in Laravel for uploading and fetching the images.

Suppose you have saved the image in the public folder under the user folder. Directory Path: public/user/

And save the image in Database like below: key: thumb_img value: "public/user/imagename.jpg"

{{ asset($userData->thumb_img) }}

You need to use the asset function for fetching the image.

Upvotes: 1

Related Questions