前端提交
$("#button").on('click',function(){ var formData =new FormData($('#form')[0]) $.ajax({ type:'post', url:'{:url("User/userAdd")}', data:formData, cache: false, contentType: false, processData: false, success: function(data) { if (data.status == 1) { layer.msg(data.info, { icon: 6, time: 1500, end: function() { parent.location.reload(); } }); } else { layer.msg(data.info, { icon: 5, time: 1500 }); } } }); });
后台接收
$file=request()->file('u_cover'); if(!empty($file)){ $info = $file->validate(['size'=>15678000,'ext'=>'jpg,png,gif'])->move( 'uploads'); if($info){ $data['u_cover']="uploads\\".$info->getSaveName(); }else{ return ['status'=>0,'info'=>$file->getError()]; } }