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

Source: Internet
Author: User
In form form

These two headers are the controllers in the controller
It is the upload of input data in form form and the operation of adding database.

function Tjkh () {$user = M (' customer ');        $uid = Session (' UserID ');        Print_r ($UID);          if (Isset ($_post[' act ')) && $_post[' act '] = = ' Tjkh ') {$sel 1 = 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");          Build the data array to write $data [' type '] = $sel 1;          $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 ($US                                Er->add ($data)) {$this->redirect (' Home/zhuye ');                                }else{$this->error (' Registration failed 7 ');                            }}else{$this->error (' Registration failed 6 ');                }}else{$this->error (' Registration failed 5 ');        }}else{$this->error (' Registration failed 4 ');                }}else{$this->error (' Registration failed 3 ');            }}else{$this->error (' Registration failed 2 ');          }}else{$this->error (' Registration failed 1 ');    }} $this->display (' Home/tjkh '); }

and
//write the action of uploading a file in form form
Public Function upload () {

        $upload = new \think\upload ();//Instantiate upload class $upload->maxsize = 2*1024*1024;//Set attachment upload size $upload->exts = array (' jpg ', ' gif ', ' PNG ', ' jpeg ', ' txt ', ' Doc ', ' wps ', ' HTML ');//Set attachment upload type $upload-&G T;savepath = './uploads/';           Set the attachment upload directory $upload->autosub = true;        $upload->subname = Array (' Date ', ' Ymd ');        $upload->replace = true;                   Upload file $info = $upload->upload ();            if (! $info) {//Upload error message $this->error ($upload->geterror ());           }else{//upload successful foreach ($info as $file) {$file [' Savepath ']. $file [' Savename ']; } $this->success (' Upload successful!        ');        } $user = M (' Up_file ');        $userid = Session (' UserID ');        $time = time ();        $NM = Date ("y-m-d h:i:s", $time);            $upload = $info [' file '] [' name ']; Save the current data Object $data [' file_img '] = $file [' SavePath ']. $file [' Savename '];        $data [' user_id '] = $userid;        $data [' file_time '] = $nm;        $data [' upload '] = $upload;                if ($userid! = "") {$user->add ($data); }    }

The corresponding two methods can be used to synchronize the two methods
Instead of implementing only one method

Reply content:

In form form

These two headers are the controllers in the controller
It is the upload of input data in form form and the operation of adding database.

function Tjkh () {$user = M (' customer ');        $uid = Session (' UserID ');        Print_r ($UID);          if (Isset ($_post[' act ')) && $_post[' act '] = = ' Tjkh ') {$sel 1 = 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");          Build the data array to write $data [' type '] = $sel 1;          $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 ($US                                Er->add ($data)) {$this->redirect (' Home/zhuye ');                                }else{$this->error (' Registration failed 7 ');                            }}else{$this->error (' Registration failed 6 ');                }}else{$this->error (' Registration failed 5 ');        }}else{$this->error (' Registration failed 4 ');                }}else{$this->error (' Registration failed 3 ');            }}else{$this->error (' Registration failed 2 ');          }}else{$this->error (' Registration failed 1 ');    }} $this->display (' Home/tjkh '); }

and
//write the action of uploading a file in form form
Public Function upload () {

        $upload = new \think\upload ();//Instantiate upload class $upload->maxsize = 2*1024*1024;//Set attachment upload size $upload->exts = array (' jpg ', ' gif ', ' PNG ', ' jpeg ', ' txt ', ' Doc ', ' wps ', ' HTML ');//Set attachment upload type $upload-&G T;savepath = './uploads/';           Set the attachment upload directory $upload->autosub = true;        $upload->subname = Array (' Date ', ' Ymd ');        $upload->replace = true;                   Upload file $info = $upload->upload ();            if (! $info) {//Upload error message $this->error ($upload->geterror ());           }else{//upload successful foreach ($info as $file) {$file [' Savepath ']. $file [' Savename ']; } $this->success (' Upload successful!        ');        } $user = M (' Up_file ');        $userid = Session (' UserID ');        $time = time ();        $NM = Date ("y-m-d h:i:s", $time);            $upload = $info [' file '] [' name ']; Save the current data Object $data [' file_img '] = $file [' SavePath ']. $file [' Savename '];        $data [' user_id '] = $userid;        $data [' file_time '] = $nm;        $data [' upload '] = $upload;                if ($userid! = "") {$user->add ($data); }    }

The corresponding two methods can be used to synchronize the two methods
Instead of implementing only one method

Call the upload () method in the Tjkh () method to return the saved path in upload ()

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.