Convert base64 to image file and write To folder in PHP with example
In this post we will give you information about Convert base64 to image file and write To folder in PHP with example. Hear we will give you detail about Convert base64 to image file and write To folder in PHP with exampleAnd how to use it also give you demo for it if it is necessary.
In this tutorial, I will let you know how to handle the images encoded with Base64 and write the images to folder.
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.
In PHP, Its very easy to get image file from Base64 encoded.
While working with canvas, you will have base64 encoded string in the form, then you will send the form data to the server using POST method and on the server, you convert them into an image file.
- $file= UPLOAD_DIR .uniqid().'.png';
<?php define('UPLOAD_DIR', 'images/'); $image_parts = explode(";base64,", $_POST['image']); $image_type_aux = explode("image/", $image_parts); $image_type = $image_type_aux; $image_base64 = base64_decode($image_parts); $file = UPLOAD_DIR . uniqid() . '.png'; file_put_contents($file, $image_base64); ?>
Laravel Intervention Summernote Editor to get upload File(image) URL instead of Base64
Hope this code and post will helped you for implement Convert base64 to image file and write To folder in PHP with example. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs