mardi 13 février 2018

Error to convert and store base64 encoding to an image in laravel 5.4

I am trying to convert and store base64 encoding to an image in laravel 5.4. Here $ifphoto has base64 value. I also checked it using return. I have visitor_photo folder in public folder. How can I store that. My controller function is here. Thanks in advance

public function store(Request $request)
    {
    $visitor = new visitor() ;
    $ifphoto = $request->v_photo; 

    if (isset($ifphoto)) {
        define('UPLOAD_DIR', 'public/visitor_photo/');

        $encoded_data = $ifphoto;
        $img          = str_replace('data:image/jpeg;base64,', '', $encoded_data );
        $data         = base64_decode($img);
        $file_name    = 'image_'.date('Y-m-d-H-i-s', time()); // You can change it to anything
        $file         = $file_name . '.png';

        $request->v_photo->move(base_path('public/visitor_photo'), $file);

       // $file         = UPLOAD_DIR . $file_name . '.png';
       // $success      = file_put_contents($file, $data);
        $visitor->v_photo = $file_name;
    }
   $visitor->save();

    return redirect('/home');

}



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire