Mar 21, 2022
0
Level 1
file_get_contents(C:\Users\dell\Documents\accounts\gna\public/storage/img/RsNR7dEIisWrF30dhrys.jpg): failed to open stream: No such file or directory
I'm new to the Laravel framework. I wrote this code following what I saw in a tutorial. I've tried to change the image upload path and executed the php artisan storage:link command but still end up with the same result. How can I solve this problem, please?
#Get auth user
$user = auth()->user();
$avatar = $this->avatar->store('img'); #Save avatar image
$path = $_SERVER['DOCUMENT_ROOT']."/storage/$avatar"; #Take the avatar's path
$type = pathinfo($path, PATHINFO_EXTENSION); #Get avatar image type
$image = file_get_contents($path); #Get the avatar image
$avatarBase64 = "data:image/$type;base64,".base64_encode($image); #Convert avatar image to base64
Storage::delete($avatar); #Delete the avatar image from the server as it is no longer needed
$user->avatar = $avatarBase64;
$user->save();
session()->flash('success', 'Avatar successfully changed!');
return redirect()->route('settings');
}
Please or to participate in this conversation.