Php ajax file upload code (1/4)

Source: Internet
Author: User
The code is as follows: Copy code

<Html>
<Body>
<H1> ajax file upload sample <Div id = result> </div>
<Pre class = js name = "code">
<Script language = webpage effect>
// Upload function
Function btn_send.onclick (){
Data = ""
Spliter = "------- 7d8d733180846"
Datadata = data + spliter + ""
Datadata = data + "content-disposition: form-data; name =" photofile "; filename =" c: \ a.txt ""
// Datadata = data + "content-type: image/pjpeg" + vbcrlf
Datadata = data + "content-type: text/plain" + "" + ""
Text = "my name is wilson lin ."
Postlength = text. length + data. length + 2 + spliter. length + 4
Package = data + text + "" + spliter + "--"

Alert (package)
// Send the xml document to the web server
Var xmlhttp = new activexobject ("microsoft. xmlhttp ");
Xmlhttp. open ("post", "./upload. php", false );
Xmlhttp. setrequestheader ("content-type", "multipart/form-data; boundary = ----- 7d8d733180846 ");
Xmlhttp. setrequestheader ("content-length", postlength );
Xmlhttp. send (package );
// Display the information returned by the server
Result. innerhtml = xmlhttp. responsetext;
}
</Script>
</Pre>
</Body>
</Html>


<Html>
<Script language = "javascript">
<! --
Var xmlhttp;
Function createxmlhttprequest (){
If (window. activexobject ){
Xmlhttp = new activexobject ("microsoft. xmlhttp ");
   }
Else if (window. xmlhttprequest ){
Xmlhttp = new xmlhttprequest ();
   }
  }
Function uploade (e ){
Var fileadd
Fileadd = e;
   
Createxmlhttprequest ();
Xmlhttp. onreadystatechange = handlestatechange;
Var url = "pic_upload.asp tutorial? Add = "+ fileadd +" & timestamp = "+ new date (). gettime ();
Xmlhttp. open ("get", url, true );
Xmlhttp. send (null );
  
  }
Function handlestatechange (){
Document. getelementbyid ("content"). innerhtml = "write progress bar ";
If (xmlhttp. readystate = 4 ){
If (xmlhttp. status = 200 ){
     
Document. getelementbyid ("content"). innerhtml = xmlhttp. responsetext;
     
    }
Else {
// Alert (xmlhttp. status );
Alert ('error, please contact the administrator! ');
     
    }
   }
  }
// -->
</Script>
<Body>
<Input type = file name = "mefile" id = "fileadd" onchange = "alert (document. getelementbyid ('fileadd'). value);">
<Input type = "submit" value = "upload" onclick = "uploade (document. getelementbyid ('fileadd'). value);">
<Div id = "content"> </div>
</Body>
</Html>

 

Homepage 1 2 3 4 Last page

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.