Laravel Base64 Image Upload
Jan 27, 2020
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....
- How to Notifications With database Driver in Laravel 11?
- How to Send Email Via Notification in Laravel 11?
- How to Install and Configure Laravel 11 Debugbar?
- How to Like Dislike System in Laravel 11?
- How to Paginate a Model with Relationship in Laravel 11?
- Laravel 11 Upload Files to Amazon S3 Example
- Laravel 11 Send WhatsApp Messages Example
- Laravel 11 Rest API Authentication Using JWT Tutorial