多图片上传(证书认证)

    use Think\Upload;
    /**
     * 上传文件
     */
    public function Img_upload($file = '')
    {
        //配置
        $config = array(
            "exts" => 'jpg,gif,png,jpeg',
        );
        $upload = new Upload($config);
        $add = $upload->upload($file);
        $path = array();
        $http = sp_get_host();
        foreach ($add as $v) {
            $path[] = $http . "/Uploads/" . trim($v['savepath'], '.') . $v['savename'];
        }
        return $path;
    }

//证书认证
    public function renzheng1(){
        // $post = json_encode($_POST);
        // $file = json_encode($_FILES);
        // $this->json('10001',array("post"=>$post,'file'=>$file));die;
        $uid = I("uid");
        $arrs = M("diploma")->where("uid='$uid'")->find();
        if($arrs){
            $this->json("10003","您已提交过资质证书,等待审核");
        }
        $d_types = I('d_type');
        $d_names = I('d_name');
        $d_mutypes = I('d_mutype');
        $date = array();
        foreach ($d_types as $key => $value) {
            $arr = array();
            $arr['uid'] = $uid;
            $arr['d_type'] = $d_types[$key];
            $arr['d_name'] = $d_names[$key];
            $arr['d_mutype'] = isset($d_mutypes[$key])?$d_mutypes[$key]:0;
            $img = $this->Img_upload(array('img'=>$_FILES['d_url'.$key]));
            $arr['d_url'] = json_encode($img);
            $arr['d_ren'] = 1;
            $arr['d_time'] = time();
            $date[] = $arr;
        }
        $rst = M("diploma")->addAll($date);
        if($rst){
            $this->json("10001","资质证书已提交,等待审核");
        } else {
            $this->json("10002","资质证书提交失败");
        }
    }
    //证书修改
    public function renzheng_save(){
        $uid = I("uid");
        $d_types = I('d_type');
        $d_names = I('d_name');
        $d_mutypes = I('d_mutype');
        $d_rens = I("d_ren");
        $date = array();
        foreach ($d_types as $key => $value) {
            $arr = array();
            $arr['uid'] = $uid;
            $arr['d_type'] = $d_types[$key];
            $arr['d_name'] = $d_names[$key];
            $arr['d_mutype'] = isset($d_mutypes[$key])?$d_mutypes[$key]:0;
            $img = $this->Img_upload(array('img'=>$_FILES['d_url'.$key]));
            $d_url = $_POST['d_url'.$key];
            $d_url = empty($d_url)?array():$d_url;
            $img = empty($img)?array():$img;
            $img = array_merge($d_url,$img);
            $arr['d_url'] = json_encode($img);
            if($d_rens[$key] ==3){
                $arr['d_ren'] = 1;
            } else {
                $arr['d_ren'] = $d_rens[$key];
            }
            $arr['d_time'] = time();
            $date[] = $arr;
        }
        M("diploma")->where("uid='$uid'")->delete();
        $rst = M("diploma")->addAll($date);
        if($rst){
            $this->json("10001","提交审核成功");
        } else {
            $this->json("10002","提交审核失败");
        }
    }

posted on 2016-12-20 15:51  *孤独的夜行者*  阅读(256)  评论(0编辑  收藏  举报

导航