<?PHPclassIndexactionextendsAction { Public functionindex () {$Photo= M (' Photo '); $list=$Photo->order (' create_time desc ')->limit (2)Select (); $this->assign (' list ',$list); $this-display (); } Public functionupload () {if(!Empty($_files)) { //If there is a file upload upload attachment $this-_upload (); //$this->forward (); } } //File Upload protected function_upload () {//I'm using a ORG.Net.UploadFile.Import ("@.org.uploadfile"); //Import Upload Class $upload=NewUploadFile (); //Set upload file size $upload->maxsize = 3292200; //set upload file type $upload->allowexts =Explode(', ', ' jpg,gif,png,jpeg '); //Set Attachments upload directory $upload->savepath = '/thinkphp/examples/file/tpl/public/uploads/'; //settings need to generate thumbnails, only valid for image files $upload->thumb =true; //Set the Reference Picture Class Library package path I'm using ORG.Util.UploadFile. $upload->imageclasspath = ' @.org.image '; //set the file suffix to generate thumbnails $upload->thumbprefix = ' M_,s_ ';//production of 2 thumbnails//set thumbnail maximum width $upload->thumbmaxwidth = ' 400,100 '; //set thumbnail maximum height $upload->thumbmaxheight = ' 400,100 '; //set upload file rules $upload->saverule =uniqid; //Delete Original $upload->thumbremoveorigin =true; if(!$upload-upload ()) { //Capturing upload Exceptions $this->error ($upload-geterrormsg ()); } Else { //get file information for successful uploads $uploadList=$upload-Getuploadfileinfo (); //ORG. Util.uploadfileImport ("@.org.image"); //add watermark to m_ thumbnail, image::water (' original filename ', ' watermark Image address ')Image::water ($uploadList[0] [' Savepath ']. ' M_ '.$uploadList[0] [' Savename '], '/thinkphp/examples/file/tpl/public/images/logo2.png '); $_post[' image '] =$uploadList[0] [' Savename ']; } $model= M (' Photo '); //Save current data Object $data[' image '] =$_post[' Image ']; $data[' create_time '] = Time(); $list=$model->add ($data); if($list!==false) { $this->success (' Upload image success! ‘); } Else { $this->error (' Upload image failed! ')); } } } ?>
thinkphp thumbnail image