webuploader 同一页面 多图上传功能

       
        
>
上传工商营业执照

   //初始化上传按钮
    var txt ='';
    var uploader = WebUploader.create({
        auto: true,
        swf: "/templates/theme/member/js/webuploader/Uploader.swf",
        server: '/attachment/attachment/uplogo.html',
        pick: {id:'.ca-up-img'},
        accept: {
            title: '上传照片',
            extensions: 'gif,jpg,jpeg,bmp,png',
            mimeTypes: 'image/!*'
        },
        compress:{
            quality: 100,
        },
        fileSingleSizeLimit: 4 * 1024 * 1024
    });
    //选择的文件出错
    uploader.on('error',function (handler) {
        switch (handler){
            case 'F_EXCEED_SIZE':
                return showerr('图片太大了,不能超过4M');
                break;
            case 'Q_EXCEED_NUM_LIMIT':
                return showerr('最多只能上传1张图片!');
                break;
        }
    });
    //文件添加队列
    uploader.on( 'fileQueued', function( file ) {
        var id=file.source.ruid,$obj=$('#rt_'+id).prev('.webuploader-pick');
            txt = $obj.html();
            $obj.html('').append('
上传中…
'); }); //上传过程 uploader.on('uploadProgress',function (file,percentage) { var id=file.source.ruid,$obj=$('#rt_'+id).prev('.webuploader-pick'); $obj.html('').append('
'+parseInt(percentage * 100)+'%
'); }); //上传成功 uploader.on('uploadSuccess',function (file,response) { uploader.removeFile(file); var id=file.source.ruid,$obj=$('#rt_'+id).prev('.webuploader-pick'); $obj.html('').html(txt); if(response.status==1){ $obj.parent('.ca-up-img').prev('.comimgs').css('background-image','url("'+response.pic+'")') $obj.parent('.ca-up-img').prev('.comimgs').attr({'data-src':response.pic,'data-name':response.msg}); }else{ return showerr(response.msg); } });

后台代码

    /**
     * 上传营业执照
     */
    public function licenseimg(){
        set_time_limit(0);
        $result=['status'=>0,'pic'=>'','msg'=>''];
        $path = "./uploadfile/photos/";
        $maxSize=1048576 * 10; //限制图片最大10M
        $img_type=array('gif','jpg','jpeg','bmp','png',);
        if(!is_writable($path)){
            $result['msg']='目录没有写权限!';
            goto _end;
        }
        if(!empty($_FILES)){
            $name = $_FILES['file']['name'];
            $size = $_FILES['file']['size'];
            $name_tmp = $_FILES['file']['tmp_name'];
            $type=explode('.',$name);
            if (empty($name)) {
                $result['msg']='您未选择图片!';
                goto _end;
            }
            if(!in_array($type[count($type)-1],$img_type)){
                $result['msg']='上传的图片类型不正确!';
                goto _end;
            }
            if($size>$maxSize){
                $result['msg']='上传的图片太大了!';
                goto _end;
            }
            $pic_name = time() . rand(1000000, 9999999) . ".jpg";
            $pic_url =$path . $pic_name;
            if (move_uploaded_file($name_tmp, $pic_url)) $result=['status'=>1,'pic'=>substr($pic_url,1),'msg'=>'上传成功!'];
            else $result=['status'=>0,'pic'=>'','msg'=>'上传失败,请重试!'];
        }
        _end:
        exit(json_encode($result));
    }

你可能感兴趣的:(PHP)