base64 image encoding conversion, wrote a method. Two parameters, one is base64 encoding and the other is the file path
<?php
/**
* base64转码图片
* @param $base64
* @param string $path
* @return bool|string
*/
function get_base64_img($base64,$path = 'data/upload/sign/'){
if (preg_match('/^(data:\s*image\/(\w+);base64,)/', $base64, $result)){
$type = $result[2];
$new_file = $path.time().".{$type}";
if (file_put_contents($new_file, base64_decode(str_replace($result[1], '', $base64)))){
return $new_file;
}else{
return false;
}
}
}
?>The above is the detailed content of PHP implements base64 transcoding into images. For more information, please follow other related articles on the PHP Chinese website!
How to modify the text in the picture
How to open php file
How to remove the first few elements of an array in php
What to do if php deserialization fails
How to connect php to mssql database
How to connect php to mssql database
What to do if the embedded image is not displayed completely
How to upload html