0

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.

5
  • See what's url it resolves to on both machines. Also please specify correct laravel version in tags, not all available. Commented Jun 6, 2020 at 16:21
  • /user/user_img_1.jpg this is what i'm getting in the image tag. Commented Jun 6, 2020 at 16:24
  • have you uploaded image at production server ? Commented Jun 6, 2020 at 16:32
  • @NikleshRaut: Yes i have uploaded Commented Jun 6, 2020 at 16:34
  • If you don't mind can you share live site url ? Commented Jun 6, 2020 at 16:35

3 Answers 3

1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

I don't think so
<img src="{{ asset($userData->thumb_img) }}"/>
1

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" />

Comments

0

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.

2 Comments

I have tried this {{ asset($userData->thumb_img) }} but it only displays text
@user3653474 , I think you had image name as user_img_1.jpg and not /user/user_img_1.jpg ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.