Heim > Backend-Entwicklung > PHP-Tutorial > MySQL – Formular-Upload und Datei-Upload können in tinkphp3.2 nicht synchronisiert werden

MySQL – Formular-Upload und Datei-Upload können in tinkphp3.2 nicht synchronisiert werden

WBOY
Freigeben: 2016-08-04 09:20:19
Original
1118 Leute haben es durchsucht

Im Formular

__URL__/upload" method="post" id="form3" enctype="multipart/form-data">

Formular 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>
Nach dem Login kopieren
Nach dem Login kopieren
Diese beiden Header befinden sich im Controller-Controller

//Was geschrieben wird, ist der Vorgang des Hochladens der normalen Daten der Eingabe in das Formular und des Hinzufügens der Datenbank

<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>
Nach dem Login kopieren
Nach dem Login kopieren
und

// schreiben den Vorgang zum Hochladen von Dateien in der 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>
Nach dem Login kopieren
Nach dem Login kopieren
Wie können wir die beiden entsprechenden Methoden synchronisieren

anstatt nur eine Methode zu implementieren

Antwortinhalt:

Im Formular

__URL__/upload" method="post" id="form3" enctype="multipart/form-data">

Formular in HTML

Diese beiden Header befinden sich im Controller-Controller
<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>
Nach dem Login kopieren
Nach dem Login kopieren
//Was geschrieben wird, ist der Vorgang des Hochladens der normalen Daten der Eingabe in das Formular und des Hinzufügens der Datenbank


und
<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>
Nach dem Login kopieren
Nach dem Login kopieren
// schreiben den Vorgang zum Hochladen von Dateien in der Form

public function upload(){

Wie können wir die beiden entsprechenden Methoden synchronisieren
<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>
Nach dem Login kopieren
Nach dem Login kopieren
anstatt nur eine Methode zu implementieren


Rufen Sie die Methode upload() in der Methode tjkh() auf und geben Sie den gespeicherten Pfad in upload() zurück

Verwandte Etiketten:
Quelle:php.cn
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage