一起源码网
标题: php实现base64转码成图片 [打印本页]
作者: 云文章 时间: 2020-4-23 15:30
标题: php实现base64转码成图片
base64图片编码转换,写了个方法。两个参数,一个是base64编码,一个是文件路径<?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;
}
}
}
?>
作者: kk670 时间: 2022-9-28 15:44
网站源码免费下载使用
| 欢迎光临 一起源码网 (https://www.171739.xyz/) |
Powered by Discuz! X3.3 |