Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

abduljakul-salsalani's avatar

How to access the files/images located at storage directory

I have it stored in the project-folder/storage/app

  <td>
    <a href="{{ storage_path('app/public/users/thumbs/' , $users->file_name ) }}"><img src="{{ storage_path('app/public/users/', $users->file_name )  }}" alt="">
 </a>
 </td>

and I have those code to refer to. I want to show it in my view. but it won't display something there

0 likes
9 replies
tisuchi's avatar

There are two ways to do that-

  • storage_path('folder/filename')
  • storage_path()/folder/filename

If your code is not working, try this way-

<a href="{{ storage_path('app/public/users/thumbs/$picture->file_name') }}">
    <img src="{{ storage_path('app/public/users/$users->file_name')  }}" alt="">
</a>

Note- Normally storage_path() return full address of storage.

Ref: https://laravel.com/docs/5.5/helpers#method-storage-path

2 likes
kenny11's avatar

tell me that after you try it. I hope you made a symlink

abduljakul-salsalani's avatar

The "public/storage" directory already exists. it says here. So laravel wants me to store it in my public directory rather than my storage ?

abduljakul-salsalani's avatar

Ahh, now I understand that when i type php artisan storage:link it will create a directory in public folder and laravel wants to access the images in views in the public folder

Snapey's avatar

only content in your public folder should be accessible to the outside world, so this could lead you to store all your images in the public folder, e.g. public/images (/images to the outside world, and if your document root is set correctly).

Laravel gives you an option to store your content in the storage/app/public folder and then create a symlink so that this folder appears to be in /public/storage

this allows you to improve security of the site since only the storage folder needs to be writeable by your application and not also parts of the public side

jekinney's avatar

@Snapey I know this is 6 years old but for reference is all:

The point of the "storage" app/public is to not override your files on deployment. Your public folder and contents (css, js, and files like images) all get overridden by default. So if you store images directly on in the public folder they will be removed by default on a typical deployment. The storage directory for the most part should be git ignored. This feature along with Lumen, came about when Envoyer was released to help with zero down time.

If you create the symlink all files linked are easily accessible through the public link so still need to be careful as you mentioned. All others inside the storage directory are protected from the outside world by default. That said, accessing files not in the public folder isn't as straight forward as using some of the Storage facade will trip errors for "A path traversal attack".

Sorry, moving on now, but just incase google brings people to this thread like it did me.

Please or to participate in this conversation.