I’m working with media files in my Laravel application. The files are being stored in the database and in the proper folders, but they are not displaying in the browser.
This is the rendered <img>
tag in the browser’s front end:
<img src="http://localhost/public/uploads/18-4f2d6e8f609942df5f746775345a9430/man.png" alt="Image">
When I navigate to <my-laravel-application-root-folder>/public/uploads/18-4f2d6e8f609942df5f746775345a9430/man.png
, the file is there, but the image won’t show on the frontend.
Here is my filesystem configuration in config/filesystems.php
:
'public' => [
'driver' => 'local',
'root' => storage_path('uploads'),
'url' => env('APP_URL') . '/public/uploads',
'visibility' => 'public',
'throw' => false,
],
I have already run the command:
php artisan storage:link
However, when I try to access the image via the URL in the rendered <img>
tag, it gives me a 404 error.
I am not sure if I am missing a step, or am doing something wrong, but what could be causing this issue, and how can I resolve it?
2
Answers
Incorrect Path Configuration in
config/filesystems.php
, The public disk configuration in yourconfig/filesystems.php
is pointing tostorage_path('uploads')
, but this is not mapped correctly to the public directory.Correct the File Path in
config/filesystems.php
You are currently pointing the public disk to storage_path(‘uploads’), which is inside the storage directory, but not directly in the public folder. Laravel’s php artisan storage:link creates a symbolic link from public/storage to storage/app/public.Update your
config/filesystems.php
configuration like this:In this case:
The files will be stored in the
storage/app/public/uploads directory.
The URL to access these files should be
http://localhost/storage/uploads/
.Now run
Update the Tag in Your Blade File
use function with img src
{{url(‘path1/path2/…..’)}}