public static function uploadBase64Img($base64_img,$type='app')
{
$base64Content = $base64_img;
$ret = '';
if(!empty($base64_img))
{
$date = date('Y-m-d',time());
存放在当前目录的upload文件夹下
if($type == 'idcard'){
$up_dir = './upload/idcard/'.$date.'/';
}elseif($type == 'users'){
$up_dir = './upload/users/'.$date.'/';
}elseif($type == 'shop'){
$up_dir = './upload/shop/'.$date.'/';
}else{
$up_dir = './upload/upimages/'.$date.'/';
}
if(!file_exists($up_dir)){
mkdir($up_dir,0777,true);
}
//$path = $up_dir;
if ($base64_img)
{
$type = "jpg";
$file_name = time()."_".mt_rand( 100000, 999999).".".$type;
$new_file = $up_dir.$file_name;
if (file_put_contents($new_file, base64_decode($base64_img)))
{
$ret = str_replace('../../..', '', $new_file);
$ret = str_replace('./', '/', $new_file);
return $ret;
}
}
}
return $ret;
}
php base64图片上传
最新推荐文章于 2023-08-16 10:25:13 发布