TP5 image Upload

Source: Internet
Author: User

1 /*image Upload*/2      Public functionupload () {3         //get a form upload file such as 001.jpg uploaded4         $file= Request ()file(' File ');5         //move to the Framework app root directory under the/public/uploads/directory6         $info=$file->validate ([' ext ' = ' jpg,png,gif '])->move (Root_path. ' Public '. Ds. ' Uploads ');7         if($info){8            //Upload information after successful upload9 //output JPGTen //echo $info->getextension (); One //Output 20160820/42a79759f284b767dfcb2a0197904287.jpg A //echo $info->getsavename (); - //Output 42a79759f284b767dfcb2a0197904287.jpg - //echo $info->getfilename (); the //echo $info->pathname; - //Get a picture of the relative path of storage -             $filePath= ' public '. Ds. ' Uploads '.$info-getsavename (); -             $getInfo=$info-getInfo (); +             //get the original name of the picture -             $name=$getInfo[' Name ']; +             //organize data, write to database A             $data= [ at' Path ' = =$filePath, -' Name ' + =$name, -' Create_time ' =Date(' y-m-d h:i:s ') -             ]; -             $affected= \think\db::name (' goods_image ')->insert ($data); -}Else{ in             //upload failed get error message -             Echo $file-GetError (); to         } +}

TP5 image Upload

Related Article

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.