PHP8.1.21版本已发布
vue8.1.21版本已发布
jquery8.1.21版本已发布

mysql - tinkphp3.2中 form表单的上传 和 文件上传不能同步

原创
2016-08-04 09:20:19 851浏览

在form表单中

或者是

html 中的form表单


        

    类型:

* 借款人姓名:

    电话:

    年龄:

    婚否:

  征信情况:

 月进账流水:

  贷款额度:

  营业执照:

 * 客服经理:

  贷款种类:

点位是否代收:

    备注:

文件材料:

上传说明:

支持上传文件类型:'jpg', 'gif', 'png', 'jpeg','txt','doc','wps','html'

支持上传文件大小:不大于 2M.

这两个表头 是Controller 控制器中的
//写的是 form表单中 input 平常数据的上传 和 添加数据库 的操作

function tjkh(){
        $user = M('customer');
        $uid = session('userid');
        print_r($uid);
        if(isset($_POST['act']) && $_POST['act'] == 'tjkh'){
          $sel1 = I('post.type');
          $name = I('post.xingm');
          $phone = I('post.phone');
          $age = I('post.age');
          $marriage = I('post.marriage');
          $cre = I('post.cre_repoting');
          $water = I('post.water');
          $lines = I('post.lines');
          $lins = I('post.license');
          $manager = I('post.manager');
          $spe = I('post.species');
          $radio =I('post.radio');
          $note =I('post.note');
          $time = time();
          $nm = date("Y-m-d",$time);
          $upload = I("post.file");
          //构建写入的数据数组 
          $data['type'] = $sel1;
          $data['name'] = $name;
          $data['phone'] = $phone;
          $data['age'] = $age;
          $data['marriage'] = $marriage;
          $data['cer_repoting'] = $cre;
          $data['income'] = $water;
          $data['lines'] = $lines;
          $data['license'] = $lins;
          $data['manage'] = $manager;
          $data['species'] = $spe;
          $data['collecting'] = $radio;
          $data['note'] = $note;
          $data['time'] = $nm;    
          $data['upload'] = $upload;
          $data['user_id'] = $uid;
          if($name != ""){
              if($phone != ""){
                  if($age != ""){
                     if($water != ""){
                         if($lines != ""){
                             if($note != ""){
                                 if($user->add($data)){
                                   $this->redirect('Home/zhuye');
                                }else{
                                    $this->error('注册失败7');
                                }
                            }else{
                                  $this->error('注册失败6');
                            }
                        }else{
                              $this->error('注册失败5');
                        }
                    }else{
                          $this->error('注册失败4');
                    }
                }else{
                      $this->error('注册失败3');
                }
            }else{
                  $this->error('注册失败2');
            }    
          }else{
              $this->error('注册失败1');
          }    
        }
        $this->display('Home/tjkh');
    }


// 写的是 form表单中 上传文件的操作
public function upload(){

        $upload = new \Think\Upload();// 实例化上传类    
        $upload->maxSize   =     2*1024*1024 ;// 设置附件上传大小    
        $upload->exts      =     array('jpg', 'gif', 'png', 'jpeg','txt','doc','wps','html');// 设置附件上传类型    
        $upload->savePath  =      './Uploads/'; // 设置附件上传目录    
        $upload->autoSub    =   true;   
        $upload->subName    =   array('date','Ymd');
        $upload->replace    =   true;
        // 上传文件     
        $info   =   $upload->upload();   
        
        if(!$info) {// 上传错误提示错误信息        
        $this->error($upload->getError());    
        }else{// 上传成功        
          foreach($info as $file){
                  $file['savepath'].$file['savename']; 
          }
          $this->success('上传成功!');
        }
        $user = M('up_file');
        $userid = session('userid');
        $time = time();
        $nm = date("Y-m-d H:i:s",$time);
        $upload = $info['file']['name'];
    
        // 保存当前数据对象
        $data['file_img'] = $file['savepath'].$file['savename'];
        $data['user_id'] = $userid;
        $data['file_time'] = $nm;
        $data['upload'] = $upload;
        if($userid != ""){
            $user->add($data);    
            }
    }

相对应的 两个方法 怎么能让 这两个方法同步
而不是只能实现一个方法

回复内容:

在form表单中

或者是

html 中的form表单


        

    类型:

* 借款人姓名:

    电话:

    年龄:

    婚否:

  征信情况:

 月进账流水:

  贷款额度:

  营业执照:

 * 客服经理:

  贷款种类:

点位是否代收:

    备注:

文件材料:

上传说明:

支持上传文件类型:'jpg', 'gif', 'png', 'jpeg','txt','doc','wps','html'

支持上传文件大小:不大于 2M.

这两个表头 是Controller 控制器中的
//写的是 form表单中 input 平常数据的上传 和 添加数据库 的操作

function tjkh(){
        $user = M('customer');
        $uid = session('userid');
        print_r($uid);
        if(isset($_POST['act']) && $_POST['act'] == 'tjkh'){
          $sel1 = I('post.type');
          $name = I('post.xingm');
          $phone = I('post.phone');
          $age = I('post.age');
          $marriage = I('post.marriage');
          $cre = I('post.cre_repoting');
          $water = I('post.water');
          $lines = I('post.lines');
          $lins = I('post.license');
          $manager = I('post.manager');
          $spe = I('post.species');
          $radio =I('post.radio');
          $note =I('post.note');
          $time = time();
          $nm = date("Y-m-d",$time);
          $upload = I("post.file");
          //构建写入的数据数组 
          $data['type'] = $sel1;
          $data['name'] = $name;
          $data['phone'] = $phone;
          $data['age'] = $age;
          $data['marriage'] = $marriage;
          $data['cer_repoting'] = $cre;
          $data['income'] = $water;
          $data['lines'] = $lines;
          $data['license'] = $lins;
          $data['manage'] = $manager;
          $data['species'] = $spe;
          $data['collecting'] = $radio;
          $data['note'] = $note;
          $data['time'] = $nm;    
          $data['upload'] = $upload;
          $data['user_id'] = $uid;
          if($name != ""){
              if($phone != ""){
                  if($age != ""){
                     if($water != ""){
                         if($lines != ""){
                             if($note != ""){
                                 if($user->add($data)){
                                   $this->redirect('Home/zhuye');
                                }else{
                                    $this->error('注册失败7');
                                }
                            }else{
                                  $this->error('注册失败6');
                            }
                        }else{
                              $this->error('注册失败5');
                        }
                    }else{
                          $this->error('注册失败4');
                    }
                }else{
                      $this->error('注册失败3');
                }
            }else{
                  $this->error('注册失败2');
            }    
          }else{
              $this->error('注册失败1');
          }    
        }
        $this->display('Home/tjkh');
    }


// 写的是 form表单中 上传文件的操作
public function upload(){

        $upload = new \Think\Upload();// 实例化上传类    
        $upload->maxSize   =     2*1024*1024 ;// 设置附件上传大小    
        $upload->exts      =     array('jpg', 'gif', 'png', 'jpeg','txt','doc','wps','html');// 设置附件上传类型    
        $upload->savePath  =      './Uploads/'; // 设置附件上传目录    
        $upload->autoSub    =   true;   
        $upload->subName    =   array('date','Ymd');
        $upload->replace    =   true;
        // 上传文件     
        $info   =   $upload->upload();   
        
        if(!$info) {// 上传错误提示错误信息        
        $this->error($upload->getError());    
        }else{// 上传成功        
          foreach($info as $file){
                  $file['savepath'].$file['savename']; 
          }
          $this->success('上传成功!');
        }
        $user = M('up_file');
        $userid = session('userid');
        $time = time();
        $nm = date("Y-m-d H:i:s",$time);
        $upload = $info['file']['name'];
    
        // 保存当前数据对象
        $data['file_img'] = $file['savepath'].$file['savename'];
        $data['user_id'] = $userid;
        $data['file_time'] = $nm;
        $data['upload'] = $upload;
        if($userid != ""){
            $user->add($data);    
            }
    }

相对应的 两个方法 怎么能让 这两个方法同步
而不是只能实现一个方法

在tjkh()方法中调用upload()方法,在upload()里返回保存的路径

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。