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