eliekhazzaka's avatar

Laravel File Storage: How to store (decoded) base64 image?

i have this code how can i store all kind of extensions jpg,jpeg, and png. in my code only storing jpg image. i need to store all images extensions. Using Laravel and API

function setFaceImage(Request $request, User $user) {

    $image = base64_decode($request->face_image);
    $storagePath = public_path() . "\" . "faceImage\FaceImage_" . $user->id . ".jpg";

    file_put_contents($storagePath, $image);

    $user->face_image = $storagePath;
    $result = $user->save();


    if($result)
    {
        $result = [
            'data' => [
                'Data Updated Successfully' ,
            ]
        ];

        return response()->json($result , 200);

    }
    else
    {
        $result = [
            'data' => [
                'The operation has failed' ,
            ]
        ];

        return response()->json($result , 200);
    }

}
0 likes
2 replies

Please or to participate in this conversation.