Gagan
Gagan

Reputation: 5656

laravel - image upload and display issues

I have a blog post application where I am uploading files to be displayed along with the post itself. I can successfully upload the image but I am unable to display it .

Here is how I am uploading it to a folder within my application..

enter image description here

and here is how i am displaying it.. enter image description here

I am uploading the image to the uploads folder under my public folder. and I am storing the image in the database as follows.. enter image description here

Although I can see that the image path is correct. I did an echo of the path that is being generated and the path to the image is correct.

Can you please let me know if there is something that I am doing wrong.

thanks

Upvotes: 2

Views: 4255

Answers (2)

Anam
Anam

Reputation: 12169

Change

$file = $file->move(public_path() . '/images/uploads',  $filename);

to

$file = $file->move('images/uploads',  $filename);

the above code will upload the picture to the public_path/images/uploads.

In your code, i can see you have used full physical path of your image directory to display the picture. Physical path only needed when you are going to upload an image.

try the following:

<img class="img-responsive" src="/images/uploads/{{ $post->thumbnail }}" >

Upvotes: 2

user2368154
user2368154

Reputation: 3

You are storing the thumbnail within the post model, but are trying to fetch it form the blog model. Try $blog->post->thumbnail instead. (If you have set a relationship)

Upvotes: 0

Related Questions