Created
November 2, 2021 04:57
-
-
Save dev-armando/12c9653902695389f3a5526d734d310a to your computer and use it in GitHub Desktop.
Transformar imagen base64 a un archivo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function fromBase64ToImg($imgBase64 , $dir , $name_file ){ | |
$pattern = '/data:image\/(.+);base64,(.*)/'; | |
preg_match($pattern, $imgBase64, $matches); | |
$imageExtension = $matches[1]; | |
$encodedImageData = $matches[2]; | |
$decodedImageData = base64_decode($encodedImageData); | |
$name = "{$name_file}.{$imageExtension}"; | |
file_put_contents("{$dir}/{$name}", $decodedImageData); | |
return "{$name}.{$imageExtension}"; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment