I'm trying to access files that are stored in storage/app/.../.../file.png.
I have created a symlink, linking my storage folder to public/storage.
When I try to access the appropriate file, my server throws a 404, saying file not found. Clearly I'm not accessing it the right way but I dont know what to change.
<img src="{{asset('storage/app/puppy/18/ax2Fk08nyWrV6TwTOnsXNCkNGuIdFebB7TTfPYGb.png')}}" alt="">
Create a symbolic link By default, public disks use local drivers and store these files under storage/app/public . To access them via the web, you need to create a symbolic link from public/storage to storage/app/public .
Laravel's filesystem configuration file is located at config/filesystems.php . Within this file, you may configure all of your filesystem "disks". Each disk represents a particular storage driver and storage location.
Laravel Symbolic link is used to link storage/app/public directory with the public directory. The easiest way to understand Symbolic link is to think a folder shortcut which we usually create in Windows. So if we add/edit/delete anything in the shortcut folder it will also reflect on the main folder and vice versa.
Change all file permissions to 644. Change all folder permissions to 755. For storage and bootstrap cache (special folders used by laravel for creating and executing files, not available from outside) set permission to 777, for anything inside. For nodeJS executable, same as above.
when you create symlink in laravel
then it create symlink of storage/app/public
folder to public/storage
folder. That means if you want to access any files publicly then place all your files inside storage/app/public
folder and access it like this
<img src="{{asset('storage/puppy/18/test.png')}}" alt="">
Here it means the file test.png
should be physically at storage/app/public/puppy/18
folder.
Execute php artisan storage:link
for creating symlink in laravel
Hope it clear you
For shared hostings try below solutions
Code:
1) Remove storage folder in public_html/public/storage
2) Create a php file for example symlink.php in public_html folder
3) Add codes to symlink.php file
$targetFolder = $_SERVER['DOCUMENT_ROOT'].'/storage/app/public';
$linkFolder = $_SERVER['DOCUMENT_ROOT'].'/public/storage';
symlink($targetFolder,$linkFolder);
echo 'Symlink process successfully completed';
4) Go to web site example.com/symlink.php
That is all...
Video url from youtube => https://www.youtube.com/watch?v=svyN8-PjGHc
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With