First, upload operation HTML interface, upload.html
<import type= ' css ' file= "Admin.css.common"/>
<import type= ' css ' file= "Admin.css.main"/>
<form action= "{: U (' Public/upload_post ')}" style= "height:40px;" enctype= "Multipart/form-data" method= "POST" >
<input type= "file" name= "photo" class= "Input-text lh30" size= "ten"/>
</form>
Second, page reference upload page
<input type= "hidden" name= "Picurl" id= "Picurl" value= ""/>
<iframe width= "100%" id= "Uploadframe" name= "uploadframe" frameborder= "0" height= "+" src= "{: U (' Public/upload ')}" ></iframe>
Third, click Submit
<input type= "Submit" onclick= "return JC ()" Name= "button" class= "btn btn82 btn_save2" value= "Save" >
<input type= "resit" name= "button" class= "btn btn82 btn_res" value= "reset" >
Iv. JS commit operation, implement upload page upload submit operation
function JC () {
if ($ (window.frames["Uploadframe"].document). Contents (). Find ("Input"). Val ()) {
$ (window.frames["Uploadframe"].document). Contents (). Find ("form"). Submit ();
return false;
}
}
Five, upload controller processing. When the upload is successful, JS causes the parent frame to submit the original form.
Public Function Upload_post () {
$upload = new \think\upload ();//instantiation of upload class
$upload->maxsize = 3145728;//Set attachment upload size
$upload->exts = array (' jpg ', ' gif ', ' PNG ', ' jpeg ');//Set attachment upload type
$upload->rootpath = './uploads/'; Set Attachments upload root directory
$upload->savepath = "; Set attachments Upload (sub) directory
Uploading files
$info = $upload->upload ();
if (! $info) {//Upload error error message
$this->error ($upload->geterror ());
}else{//Upload Success
Echo ' <script>parent.document.getelementbyid ("Picurl"). Value= "'. $info ["Photo"] [' Savepath ']. $info ["Photo"] [' savename ']. ' ";
Parent.document.getElementById ("Myfrom"). Submit (); </script> ';
$this->success (' Upload successful! ‘);
}
}