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