yigitozmen's avatar

print image from storage_path

I'm using laravel 5.3 right now.

Now i am uploading images belons to image serial number. For example, uploaded image would be stored there: /storage/app/serialNumber/imagename.jpg then saved to the database filename with folder like this: serialNumber/imagename.jpg

When i want to show image on page i try this:

img src="{{Storage:get($filename)}}"> and it does nothing. I see empty on source.

When i try this: img src="{{ storage_path().'/app/'.$filename }}"> says 404 but in source path is right.

So, how can i print image to the page?

0 likes
3 replies
davielee's avatar
davielee
Best Answer
Level 11

@yigitozmen The storage directly is not publically viewable, therefore just trying to get it directly from a URL won't work. The Storage facade has access to a method called url() that when used with the local driver will end up giving you a url like the following.

http://example.com/storage/serialNumber/imagename.jpg

In order to do something like this though, Laravel want's you to follow a convention it is expecting. The following is an except from the docs.

Remember, if you are using the local driver, all files that should be publicly accessible should be placed in the storage/app/public directory. Furthermore, you should create a symbolic link at public/storage which points to the storage/app/public directory.

Give that a go and see if that will work for you :)

yigitozmen's avatar

@craigpaul hi again. Now i tried to make this. I saved the file under the storage/app/pulic/fileserialno/ now Storage::url() returns the path

for example: /storage/aaa111222/d8a167546baab742fdd0b1757982bae9.jpeg

but still i can't see the image.

Please or to participate in this conversation.