Laravel: Save Base64 .png file to public folder from controller

后端 未结 8 1756
灰色年华
灰色年华 2021-02-05 07:46

I send a png image file to controller in base64 via Ajax. I\'ve already test and sure that controller has received id but still can\'t save it to public folder.

8条回答
  •  面向向阳花
    2021-02-05 08:01

    what am i doing is using basic way

    $file = base64_decode($request['profile_pic']);
                $folderName = '/uploads/users/';
                $safeName = str_random(10).'.'.'png';
                $destinationPath = public_path() . $folderName;
                file_put_contents(public_path().'/uploads/users/'.$safeName, $file);
    
               //save new file path into db
                $userObj->profile_pic = $safeName;
            }
    

提交回复
热议问题