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

后端 未结 8 1754
灰色年华
灰色年华 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 07:59

    $file = base64_decode($request['image']);
            $folderName = 'public/uploads/';
            $safeName = str_random(10).'.'.'png';
            $destinationPath = public_path() . $folderName;
            $success = file_put_contents(public_path().'/uploads/'.$safeName, $file);
            print $success;
    

提交回复
热议问题