I hosted laravel application on shared hosting server. on server there are 2 folders :
1) laravelapp -> contains (app,config,database,vendor...etc folders)
2) public_html -> contains (css,js,images,storage folders)
I use below code to upload image :
if($request->hasFile('file')){
$filenameWithExt=$request->file('file')->getClientOriginalName();
$filename=pathinfo($filenameWithExt,PATHINFO_FILENAME);
$extension=$request->file('file')->getClientOriginalExtension();
$fileNameToStore=str_slug($filename,'_').'_'.time().'.'.$extension;
request()->file->move(public_path('storage/profile'), $fileNameToStore);
$image="/storage/profile/".$fileNameToStore;
}
It is successfully upload file to laravelapp/public/storage/profile
folder
I have created symlink to laravelapp/public/storage
with public_html/storage
in database : imagepath is saved as /storage/profile/user1.png
in blade template i use : <img src="{{$img}}" />
but imageurl :
www.mydomain.com/storage/profile/user1.png redirect to 404 page and image not displaying .
anyone please help me to solve problem.
This worked for me on a shared hosting server:
edit your config/filesystems.php
and modify the public
part like this
'public' => [
'driver' => 'local',
'root' => storage_path(),
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
]
Notice that the storage_path() does not take any argument. Now remove storage
folder from your public
directory if already exists, then do:
php artisan storage:link
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