TP5通用图片上传接口
作者:项羽 •
/**
* 通用图片上传接口
* @return \think\response\Json
*/
public function upload()
{
$file = request()->file("image");
if($file){
$info = $file->move(ROOT_PATH . 'public' . DS . 'uploads');
if($info){
$a=$info->getSaveName();
$imgp= str_replace("\\","/",$a);
$imgpath='/uploads/'.$imgp;
$data['f_img']= $imgpath;
$ret['code']=1;
$ret['message']='上传成功';
$ret['data']=$data;
}else{
// 上传失败获取错误信息
$ret['code']=0;
$ret['message']='上传失败';
$ret['data']=$file->getError();
}
return json($ret);
}
}