Home  >  Article  >  Backend Development  >  mysql - form upload and file upload cannot be synchronized in tinkphp3.2

mysql - form upload and file upload cannot be synchronized in tinkphp3.2

WBOY
WBOYOriginal
2016-08-04 09:20:191102browse

In the form

or

form form in html

<code><form action="__URL__/upload" method="post" id="form3" enctype="multipart/form-data">
        <p style="margin-top: 10px;">
            <span id="" >
                    类型:
            </span>
            <select name="type"  id="type" onchange="selectInput(this)"> 
                     <option  value="房抵贷" selected="selected">房抵贷</option> 
                     <option  value="垫资贷">垫资贷</option> 
                     <option  value="企业贷">企业贷</option> 
                     <option  value="暂无1">暂无1</option> 
                     <option  value="暂无2">暂无2</option> 
                     <option  value="提醒通知">提醒通知</option> 
                     <option  value="银行栏目">银行栏目</option> 
            </select>
        </p>
        <p>
            <span id="">
                <a style="color: red;">*</a>
                借款人姓名:
            </span>
            <input type="text" name="xingm" id="xingm" value="" />
        </p>    
        <p>
            <span id="">
                    电话:
            </span>
            <input type="text" name="phone" id="phone" value="" />
        </p>         
        <p>
            <span id="">
                    年龄:
            </span>
            <input type="text" name="age" id="age" value="" />
        </p>             
        <p>
            <span id="">
                    婚否:
            </span>
            <select id="marriage" name="marriage" > 
                <option value="是" selected="selected">是</option>
                <option value="否">否</option>
            </select>
        </p>
        <p>
            <span id="">
                  征信情况:
            </span>
            <select  id="cre_repoting" name="cre_repoting" > 
                <option value="优" selected="selected">优</option>
                <option value="良">良</option>
                <option value="差">差</option>
            </select>
        </p>
        <p>
            <span id="">
                 月进账流水:
            </span>
            <input type="text" name="water" id="water" value="" />
            <span id="" >万</span>
        </p>             
        <p>
            <span id="">
                  贷款额度:
            </span>
            <input type="text" name="lines" id="lines" value="" />
            <span id="" >万</span>
        </p>
        <p>
            <span id="">
                  营业执照:
            </span>
            <select id="license" name="license"> 
                <option value="有" selected="selected">有</option>
                <option value="无">无</option>
            </select>
        </p>
        <p>
            <span id="">
                 <a style="color: red;">*</a>
                客服经理:
            </span>
            <select id="manager" name="manager">
                <option value="张" selected="selected">张</option>
                <option value="王">王</option>
                <option value="李">李</option>
            </select>
        </p>
        <p>
            <span id="">
                  贷款种类:
            </span>
            <select id="species" name="species"> 
                <option value="先息后本" selected="selected">先息后本</option>
                <option value="等额本息">等额本息</option>
                <option value="等额本金">等额本金</option>
            </select>
        </p>
        <p>
            <span id="">
                点位是否代收:
            </span>
            <input type="radio" name="radio" id="radio" value="01" checked style="width: 3em;">是
            <input type="radio" name="radio" id="radio" value="02"  style="width: 3em;">否
        </p>
        <p>
            <span id="">
                    备注:
            </span>
            <textarea id="note" name="note"></textarea> 
        </p>
        <p>
            <span id="">
                文件材料:
            </span>
            
            <input type="file" name="file" style="margin-top: 1em;" >
                <item label="本地上传" onclick="doFileBrowse(this);"/>
            </input>
        </p>
         <p>上传说明:</p>
          <p>支持上传文件类型:'jpg', 'gif', 'png', 'jpeg','txt','doc','wps','html'</p>
          <p>支持上传文件大小:不大于 2M.</p>
        <input type="hidden" name="act" id="act" value="tjkh" />
        <input type="submit" value="提交" onclick="return subk()"/>
    </form>    </code>

These two headers are in the Controller controller
//What is written is the operation of uploading normal data and adding database to the input in the form

<code>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');
    }</code>

and
// write the operation of uploading files in the form
public function upload(){

<code>        $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);    
            }
    }</code>

How can we synchronize two corresponding methods
instead of only implementing one method

Reply content:

In the form
or

form form in html

<code><form action="__URL__/upload" method="post" id="form3" enctype="multipart/form-data">
        <p style="margin-top: 10px;">
            <span id="" >
                    类型:
            </span>
            <select name="type"  id="type" onchange="selectInput(this)"> 
                     <option  value="房抵贷" selected="selected">房抵贷</option> 
                     <option  value="垫资贷">垫资贷</option> 
                     <option  value="企业贷">企业贷</option> 
                     <option  value="暂无1">暂无1</option> 
                     <option  value="暂无2">暂无2</option> 
                     <option  value="提醒通知">提醒通知</option> 
                     <option  value="银行栏目">银行栏目</option> 
            </select>
        </p>
        <p>
            <span id="">
                <a style="color: red;">*</a>
                借款人姓名:
            </span>
            <input type="text" name="xingm" id="xingm" value="" />
        </p>    
        <p>
            <span id="">
                    电话:
            </span>
            <input type="text" name="phone" id="phone" value="" />
        </p>         
        <p>
            <span id="">
                    年龄:
            </span>
            <input type="text" name="age" id="age" value="" />
        </p>             
        <p>
            <span id="">
                    婚否:
            </span>
            <select id="marriage" name="marriage" > 
                <option value="是" selected="selected">是</option>
                <option value="否">否</option>
            </select>
        </p>
        <p>
            <span id="">
                  征信情况:
            </span>
            <select  id="cre_repoting" name="cre_repoting" > 
                <option value="优" selected="selected">优</option>
                <option value="良">良</option>
                <option value="差">差</option>
            </select>
        </p>
        <p>
            <span id="">
                 月进账流水:
            </span>
            <input type="text" name="water" id="water" value="" />
            <span id="" >万</span>
        </p>             
        <p>
            <span id="">
                  贷款额度:
            </span>
            <input type="text" name="lines" id="lines" value="" />
            <span id="" >万</span>
        </p>
        <p>
            <span id="">
                  营业执照:
            </span>
            <select id="license" name="license"> 
                <option value="有" selected="selected">有</option>
                <option value="无">无</option>
            </select>
        </p>
        <p>
            <span id="">
                 <a style="color: red;">*</a>
                客服经理:
            </span>
            <select id="manager" name="manager">
                <option value="张" selected="selected">张</option>
                <option value="王">王</option>
                <option value="李">李</option>
            </select>
        </p>
        <p>
            <span id="">
                  贷款种类:
            </span>
            <select id="species" name="species"> 
                <option value="先息后本" selected="selected">先息后本</option>
                <option value="等额本息">等额本息</option>
                <option value="等额本金">等额本金</option>
            </select>
        </p>
        <p>
            <span id="">
                点位是否代收:
            </span>
            <input type="radio" name="radio" id="radio" value="01" checked style="width: 3em;">是
            <input type="radio" name="radio" id="radio" value="02"  style="width: 3em;">否
        </p>
        <p>
            <span id="">
                    备注:
            </span>
            <textarea id="note" name="note"></textarea> 
        </p>
        <p>
            <span id="">
                文件材料:
            </span>
            
            <input type="file" name="file" style="margin-top: 1em;" >
                <item label="本地上传" onclick="doFileBrowse(this);"/>
            </input>
        </p>
         <p>上传说明:</p>
          <p>支持上传文件类型:'jpg', 'gif', 'png', 'jpeg','txt','doc','wps','html'</p>
          <p>支持上传文件大小:不大于 2M.</p>
        <input type="hidden" name="act" id="act" value="tjkh" />
        <input type="submit" value="提交" onclick="return subk()"/>
    </form>    </code>

These two headers are in the Controller controller
//What is written is the operation of uploading normal data and adding database to the input in the form

<code>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');
    }</code>

and
// write the operation of uploading files in the form
public function upload(){

<code>        $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);    
            }
    }</code>

How can we synchronize two corresponding methods
instead of only implementing one method

mysql - form upload and file upload cannot be synchronized in tinkphp3.2Call the upload() method in the tjkh() method, and return the saved path in upload()

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:nginx errorNext article:nginx error