TP Upload Image

Source: Internet
Author: User

    //update in the words, be sure to write that if judgment     Public functionUpdate () {$model= M (' link '); $upload=New\think\upload ();//instantiating an upload class        $upload->maxsize = 3145728;//set attachment upload size        $upload->exts =Array(' jpg ', ' gif ', ' PNG ', ' jpeg ');//set attachment upload type        $upload->rootpath = './public '; Public under the root$upload->savepath = '/uploads/';//Set Attachments upload directory        $upload->savename = [' uniqid ', ' pic '];//Set Save prefix        $upload->subname = [' Date ', ' y/m/d ']; Save As Date//uploading files and returning information        $info=$upload-upload (); if($info) {//update, be sure to write this judgment//traversal information Get path and file name            foreach($info  as $file){                $img= ' public '.$file[' Savepath '].$file[' Savename ']; }            //Save the file name in post to make it easy to create            $_post[' picname '] =$img; }                                                if($model-Create ()) {            $model-Save (); $this->success (' Update succeeded ', U ("Link/select")); }Else{            $this->error (' update failed ', U ("Link/select")); }            }    

2. Add ....

    //Save the added content     Public functionInsert () {$model= M (' link '); $upload=New\think\upload ();//instantiating an upload class                  $upload->maxsize = 3145728;//set attachment upload size         $upload->exts =Array(' jpg ', ' gif ', ' PNG ', ' jpeg ');//set attachment upload type         $upload->rootpath = './public ';//Root         $upload->savepath = '/uploads/';//Set Attachments upload directory         $upload->subname = [' Date ', ' y/m/d '];//Create a folder as a date save picture         $upload->savename = [' uniqid ', ' pic '];//Set Save prefix                           $info=$upload->upload ();//upload File//Array (size=1)//' picname ' +//Array (SIZE=9)//' name ' = = String ' meinv002.jpg ' (len GTH=12)//' type ' = = String ' Image/jpeg ' (length=10)//' size ' = = int 557301//' key ' = = = String ' PICN Ame ' (length=7)//' ext ' = = string ' jpg ' (length=3)//' md5 ' = = String ' 6807fdb5a7d40d72374f0049c46fb70d ' (l  ENGTH=32)//' sha1 ' = = String ' 8f9b545211b2dfa49957cf3e0e8f5e8cd68a734e ' (length=40)//' savename ' + = string ' Pic55c74c898d07d.jpg ' (length=20)//' Savepath ' = "string '/uploads/2015/08/09/' (length=20//dump ($upload );//echo '                 foreach($info  as $file){            $img= ' public '.$file[' Savepath '].$file[' Savename ']; }                $_post[' picname '] =$img; Give him the name .if($model-Create ()) {            $model->addtime = Time(); $model-Add (); $this->success (' Add Success ', U ("Link/select")); }Else{            $this->error (' Commit failed ', U ("Link/select")); }    }



Third, the form

<form role= "form" action= ' __url__/insert ' method= ' POST ' enctype= ' Multipart/form-data ' >

            class= "Form-group" >                <label> Add picture </label>                <input type= "file" name= "Picname" >            </div>

TP Upload Image

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.