Table of Contents
Reply content:
Home Backend Development PHP Tutorial mysql - form upload and file upload cannot be synchronized in tinkphp3.2

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

Aug 04, 2016 am 09:20 AM
mysql php thinkphp

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>
Copy after login
Copy after login

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>
Copy after login
Copy after login

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>
Copy after login
Copy after login

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>
Copy after login
Copy after login

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>
Copy after login
Copy after login

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>
Copy after login
Copy after login

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 of this Website
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

How to fix mysql_native_password not loaded errors on MySQL 8.4 How to fix mysql_native_password not loaded errors on MySQL 8.4 Dec 09, 2024 am 11:42 AM

One of the major changes introduced in MySQL 8.4 (the latest LTS release as of 2024) is that the &quot;MySQL Native Password&quot; plugin is no longer enabled by default. Further, MySQL 9.0 removes this plugin completely. This change affects PHP and other app

How To Set Up Visual Studio Code (VS Code) for PHP Development How To Set Up Visual Studio Code (VS Code) for PHP Development Dec 20, 2024 am 11:31 AM

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

How do you parse and process HTML/XML in PHP? How do you parse and process HTML/XML in PHP? Feb 07, 2025 am 11:57 AM

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

PHP Program to Count Vowels in a String PHP Program to Count Vowels in a String Feb 07, 2025 pm 12:12 PM

A string is a sequence of characters, including letters, numbers, and symbols. This tutorial will learn how to calculate the number of vowels in a given string in PHP using different methods. The vowels in English are a, e, i, o, u, and they can be uppercase or lowercase. What is a vowel? Vowels are alphabetic characters that represent a specific pronunciation. There are five vowels in English, including uppercase and lowercase: a, e, i, o, u Example 1 Input: String = "Tutorialspoint" Output: 6 explain The vowels in the string "Tutorialspoint" are u, o, i, a, o, i. There are 6 yuan in total

Top 10 PHP CMS Platforms For Developers in 2024 Top 10 PHP CMS Platforms For Developers in 2024 Dec 05, 2024 am 10:29 AM

CMS stands for Content Management System. It is a software application or platform that enables users to create, manage, and modify digital content without requiring advanced technical knowledge. CMS allows users to easily create and organize content

7 PHP Functions I Regret I Didn't Know Before 7 PHP Functions I Regret I Didn't Know Before Nov 13, 2024 am 09:42 AM

If you are an experienced PHP developer, you might have the feeling that you’ve been there and done that already.You have developed a significant number of applications, debugged millions of lines of code, and tweaked a bunch of scripts to achieve op

How to Add Elements to the End of an Array in PHP How to Add Elements to the End of an Array in PHP Feb 07, 2025 am 11:17 AM

Arrays are linear data structures used to process data in programming. Sometimes when we are processing arrays we need to add new elements to the existing array. In this article, we will discuss several ways to add elements to the end of an array in PHP, with code examples, output, and time and space complexity analysis for each method. Here are the different ways to add elements to an array: Use square brackets [] In PHP, the way to add elements to the end of an array is to use square brackets []. This syntax only works in cases where we want to add only a single element. The following is the syntax: $array[] = value; Example

See all articles