Laravel Base64 Image Upload

Admin   Laravel   1499  2021-03-16 10:10:40

Hi Guys,

In this example,I will learn you how to easy convert base64 image upload in can easy and simply convert to base64 image upload in laravel.i will write simple code for save base64 encoded image to file using php and you can save it png, jpg as you want.

While working with API for app, You will notice that they will send the format of images in Base64 encoded. So in that case, you will need to move the Base64 encoded images to server as a image file.

Here in this example i write function createImage() from base64 string. you can simply follow bellow example:

example :




public function createImage($img)


$folderPath = "images/";

$image_parts = explode(";base64,", $img);

$image_type_aux = explode("image/", $image_parts[0]);

$image_type = $image_type_aux[1];

$image_base64 = base64_decode($image_parts[1]);

$file = $folderPath . uniqid() . '. '.$image_type;

file_put_contents($file, $image_base64);



It will help you....