thinkphp about IFRAME One commit completes all operations

Source: Internet
Author: User

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! ‘);
}
}

  

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.