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.
- <?php
- define('UPLOAD_DIR','images/');
- $image_parts=explode(";base64,",$_POST['image']);
- $image_type_aux=explode("image/",$image_parts[]);
- $image_type=$image_type_aux[1];
- $image_base64=base64_decode($image_parts[1]);
- $file= UPLOAD_DIR .uniqid().'.png';
- file_put_contents($file,$image_base64);
- ?>
<?php
define('UPLOAD_DIR', 'images/');
$image_parts = explode(";base64,", $_POST['image']);
$image_type_aux = explode("image/", $image_parts[0]);
$image_type = $image_type_aux[1];
$image_base64 = base64_decode($image_parts[1]);
$file = UPLOAD_DIR . uniqid() . '.png';
file_put_contents($file, $image_base64);
?>
How to revoke 'git add' before 'git commit' ?
In this post we will give you information about How to revoke 'git add' before 'git commit' ?. Hear we will give you detail about How to revoke 'git add' before 'git commit' ?And how to use it also give you demo for it if it is necessary.
Sometimes you need to undo your git file before you git comment command. Because you made a some misteck or wrong code and you did git add using "git add ." command then you think how to undo your code before git commit command. But you can do that using git reset command, if you need to undo all file Or you may need to undo just one then you can do using git reset command, you can see bellow command.
Example:
// For Spesific filegit reset
// For all files
git reset
Hope this code and post will helped you for implement How to revoke 'git add' before 'git commit' ?. 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
Laravel Intervention Summernote Editor to get upload File(image) URL instead of Base64
Try this..
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