您现在的位置是: 网站首页>详情 文章详情

TP5.1 ajax图片上传

erhas2019-12-19 10:49:45php

前端提交

$("#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()];                       
    }
}


上一篇:tp5 事务处理

下一篇:没有了...