Maison  >  Article  >  développement back-end  >  mysql - tinkphp3.2中 form表单的上传 和 文件上传不能同步

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

WBOY
WBOYoriginal
2016-08-04 09:20:191103parcourir

在form表单中

或者是

html 中的form表单

<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>房抵贷</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>是</option>
                <option value="否">否</option>
            </select>
        </p>
        <p>
            <span id="">
                  征信情况:
            </span>
            <select id="cre_repoting" name="cre_repoting"> 
                <option value="优" 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>有</option>
                <option value="无">无</option>
            </select>
        </p>
        <p>
            <span id="">
                 <a style="color: red;">*</a>
                客服经理:
            </span>
            <select id="manager" name="manager">
                <option value="张" selected>张</option>
                <option value="王">王</option>
                <option value="李">李</option>
            </select>
        </p>
        <p>
            <span id="">
                  贷款种类:
            </span>
            <select id="species" name="species"> 
                <option value="先息后本" 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);"></item>
            
        </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>

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

<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>


// 写的是 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>

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

回复内容:

在form表单中

或者是

html 中的form表单

<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>房抵贷</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>是</option>
                <option value="否">否</option>
            </select>
        </p>
        <p>
            <span id="">
                  征信情况:
            </span>
            <select id="cre_repoting" name="cre_repoting"> 
                <option value="优" 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>有</option>
                <option value="无">无</option>
            </select>
        </p>
        <p>
            <span id="">
                 <a style="color: red;">*</a>
                客服经理:
            </span>
            <select id="manager" name="manager">
                <option value="张" selected>张</option>
                <option value="王">王</option>
                <option value="李">李</option>
            </select>
        </p>
        <p>
            <span id="">
                  贷款种类:
            </span>
            <select id="species" name="species"> 
                <option value="先息后本" 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);"></item>
            
        </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>

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

<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>


// 写的是 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>

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

mysql - tinkphp3.2中 form表单的上传 和 文件上传不能同步在tjkh()方法中调用upload()方法,在upload()里返回保存的路径

Déclaration:
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn
Article précédent:nginx报错Article suivant:上传视频到服务器相关问题