First look at the HTML add a form, note here the action path to select the right.
<Div> <formAction= "__url__/add_img"enctype= "Multipart/form-data"Method= "POST"style= "padding:10px;" >Image width:<inputtype= "text"name= "width" />Image length:<inputtype= "text"name= "height" /> <inputtype= "File"name= "Photo" /> <inputtype= "Submit"value= "Submit" > </form> </Div>
Then add the following code to the controller:
functionadd_img () {if($_post[' Width ']&&$_post[' Height ']) { $rs=import (' ORG.Net.UploadFile '); $upload=NewUploadFile (); $upload->maxsize=2097153;//set the upload file size to 2M $root _path=bath_path;//wait for the upload. $sub _path= '/image/wapphoto/';//everything in order to upload $upload->savepath =bath_path. ' /image/wapphoto/';//Set Attachments upload directory $upload->allowexts =Array(' jpg ', ' gif ', ' PNG ', ' jpeg ');//set attachment upload type $upload->thumb =true; $upload->thumbmaxwidth =$_post[' Width ']; $upload->thumbmaxheight =$_post[' Height ']; $file->thumbpath=bath_path. ' /image/wapphoto/';//Thumbnail save path $file->thumbremoveorigin=true;//generate thumbnails to delete the original picture if(!$upload-upload ()) {//Upload error message $this->error ($upload-geterrormsg ()); }Else{//upload successfully get upload file information $info=$upload-Getuploadfileinfo (); //$size =$_post[' width ']. ' * '. $_post[' height ']; Print_r ($info); $model=m (' Wap_photo '); $model->photo=$sub _path.‘ Thumb_ '.$info[0] ["Savename"]; $model->size=$_post[' width ']. ' *‘.$_post[' Height ']; $model- Time= Time(); $model-Add (); $this->success ("Data saved successfully!")); } }Else { Echo' Upload failed '; return false; }}
Thinkphp 3.0 version upload file plus picture thumbnail instance parsing