/**
* 上传图片
*/
public function ImgUpload(){
$id = input('id');
$image['imageo'] = input('imageo'); //驾驶证
$image['imaget'] = input('imaget'); //行驶证
$phone = [];
foreach($image as $key=>$im){
$phone[$key] = $this->BasePic($im);
}
$phone = serialize($phone);
$date['image'] = $phone;
$result = model('test')->Updatetest($id,$date);
if ($result) {
_ajaxReturn(200,'操作成功',$result);
}
_ajaxReturn(201,'操作失败');
}
/**
* base64码转为图片
*/
public function BasePic($image){
$imageName = md5("25220_".date("His",time())."_".rand(1111,9999)).'.png';//图片名称
if (strstr($image,",")){
$image = explode(',',$image);
$image = $image[1];
}
$path = "uploads/".date("Ymd",time());//路径
if (!is_dir($path)){ //判断目录是否存在 不存在就创建
mkdir($path,0777,true);
}
$imageSrc= $path."/". $imageName; //图片名字
$r = file_put_contents(ROOT_PATH ."public/".$imageSrc, base64_decode($image));//返回的是字节数
$imageSrc = config('http_url')."/".$path."/". $imageName;//保存路径
if (!$r) {
return json(['data'=>null,"code"=>1,"msg"=>"图片生成失败"]);
}else{
return $imageSrc;
}
}