Laravel Base64 Image Upload

10-Apr-2023

.

Admin

Hi Guys,

In this example,I will learn you how to easy convert base64 image upload in laravel.you 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 :


<?php

createImage($_POST['image']);

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....

#Laravel 7

#Laravel

#PHP

#Laravel 6