/*
* base64图片上传
* @param string $base64_img 图片数据流
* @return string|bool
*/
public function base64img($base64_img)
{
$up_dir = dirname(__DIR__).'/web/uplodes/image/';
if(preg_match('/^(data:s*image/(w+);base64,)/', $base64_img, $result)){
$type = $result[2];
//判断图片类型
if(in_array($type,array('pjpeg','jpeg','jpg','gif','bmp','png')))
{
$new_file = $up_dir.date('YmdHis').'.'.$type;
$returnurl = Yii::$app->params['IMGURL'].'/uplodes/image/'.date('YmdHis').'.'.$type;
if(file_put_contents($new_file, base64_decode(str_replace($result[1], '', $base64_img))))
{
return ['message'=>'上传成功','data'=>$returnurl,'code'=>200];
}else{
return ['message'=>'上传失败','data'=>[],'code'=>400];
}
}else{
//文件类型错误
return ['message'=>'类型错误','data'=>[],'code'=>400];
}
}else{
//文件错误
return ['message'=>'文件错误','data'=>[],'code'=>400];
}
}
/**
* @api {post} uplode/uploadimg 图片路径
* @apiDescription 图片路径
* @apiParam {String} image 图片文件
* @apiGroup Uplodes
* @apiPermission ???
* @apiVersion 1.1.0
* @apiSuccessExample {json} Success-Response:
{
"code": "200