tp5--图片上传
/**
* 图片上传
*/
public function uploadd(){
$file=request()->file('file');
$arr=[];
if($file){
$info = $file->validate(['size'=>156780,'ext'=>'jpg,png,gif'])->move(ROOT_PATH . 'public' . DS . 'uploads');
if($info){
$arr['code']=1;
$arr['msg']=$info->getSaveName();
}else{
$arr['code']=3;
$arr['msg']=$file->getError();
}
}else{
$arr['code']=2;
$arr['msg']='没有上传文件';
}
return $arr;
}
var uploadInst = upload.render({
elem: '#test1' //绑定元素
,url: '{:url("login/uploadd")}' //上传接口
,done: function(res){
//上传完毕回调
if(res.code == 1){
$('#imgs').attr('src','/uploads/'+res.msg);
$('#gimg').val('/uploads/'+res.msg);
}else{
layer.msg(res.msg);
}
}
});