Failed to initialize data from binary data

I am trying to save a base64 encoded image using Intervention Image, laravel-5 Exception told me "Cannot initialize data from binary data". can anyone help?

$png_url = "user-".time().".png";
$path = "/public/".$png_url;
Image::make(base64_encode($request['image']))->save($path);

      

+6


source to share


2 answers


<?php
$png_url = "user-".time().".png";
$path = "/public/".$png_url;
$base=base64_decode($request['image']);
Image::make($base)->save($path);
?>

      



+5


source


If your code works well on your localhost and you are uploading it to a running server and you encounter an error like this, sometimes it is caused by a path problem on Windows Server and Ubuntu / etc.

In my case, I changed everything \

in my path to/

I.e:

Image::make(base64_decode($request['profile_pic']))->save(public_path('cdn\profile_pictures\/'.$imageName))->destroy();

      



from

before

Image::make(base64_decode($request['profile_pic']))->save(public_path('cdn/profile_pictures//'.$imageName))->destroy();

      

Hope this helps someone ... Happy coding ...

0


source







All Articles