如果是多图片上传直接forecho循环$image即可;
public function base64(){
//接收base64数据
$image= $_POST['imegse'];
//设置图片名称
$imageName = "25220_".date("His",time())."_".rand(1111,9999).'.png';
//判断是否有逗号 如果有就截取后半部分
if (strstr($image,",")){
$image = explode(',',$image);
$image = $image[1];
}
//设置图片保存路径
$path = "./".date("Ymd",time());
//判断目录是否存在 不存在就创建
if (!is_dir($path)){
mkdir($path,0777,true);
}
//图片路径
$imageSrc= $path."/". $imageName;
//生成文件夹和图片
$r = file_put_contents($imageSrc, base64_decode($image));
if (!$r) {
return json_encode(['code'=>0,'message'=>'图片生成失败']);
}else {
return json_encode(['code'=>1,'message'=>'图片生成成功']);
}
}
本博客内容为转载,转载地址为:https://www.cnblogs.com/junyi-bk/p/11742278.html