I am having trouble uploading a user image to my public folder. The file name generates correctly, and saves the name to my database, except the iamge itself refuses to get saved into my public folder. What am I doing wrong?
public function update_avatar(Request $request) {
if($request->hasFile('avatar')) {
$avatar = $request->file('avatar');
$filename = time() . "." . $avatar->getClientOriginalExtension();
Image::make($avatar)->resize(300,300)->save(public_path('/uploads/'.$filename)); ==> This is causing me errors
user = Auth::user();
$user->avatar = $filename;
$user->save();
}
The public disk is intended for files that are going to be publicly accessible. By default, the
publicdisk uses the local driver and stores these files instorage/app/public. To make them accessible from the web, you should create a symbolic link frompublic/storagetostorage/app/public. This convention will keep your publicly accessible files in one directory that can be easily shared across deployments.To create the symbolic link, you may use the
storage:linkArtisan command:
php artisan storage:link
https://laravel.com/docs/5.5/filesystem
I think you should try this:
$destinationPath = public_path('uploads');
Image::make($avatar)->resize(300,300)->save($destinationPath.'/'.$filename);
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