PHP Ajax File Upload Example Analysis _php tutorial

Source: Internet
Author: User
How to implement asynchronous file uploads
With the support of the file FileReader object, asynchronous file uploads will be simple. (The form was previously submitted to the IFRAME for implementation)
1: Get the File object
2: Read 2 binary data
3: Simulate HTTP requests, send data (usually troublesome here)
Sending data using the Sendasbinary method of the XMLHttpRequest object under Forefox;
4: Perfect Realization
Problems encountered
Currently only Firefox can upload files correctly. (Chrome can also take google.gears upload)
The file data read from Firefox and Chrome doesn't seem to be the same (I don't know if this is the reason for debugging the tool)
Chrome and other advanced browsers do not have the Sendasbinary method to send data only using the Send method, which may be the reason for the failure to upload correctly. (Test normal text files can be uploaded correctly)






<title>HTML5 file and FileReader</title>





(Drag the picture here) use FileReader to get the file base64 encoding










FileReader Object

var filereader = new FileReader ();
Filereader.onloadend = function () {
Console.log (this.readystate); It's supposed to be 2 this time.
Console.log (This.result); Read completion callback function, data saved in result
}
filereader.readasbinarystring (file);//start reading 2 binary data asynchronous parameter to file object
Filereader.readasdataurl (file); Read Base64
Filereader.readastext (file);//Read text information

You can run the following simple example (Chrome and Firefox are available)


http://www.bkjia.com/PHPjc/444779.html www.bkjia.com true http://www.bkjia.com/PHPjc/444779.html techarticle How to implement asynchronous file uploads with the support of the file FileReader object, the asynchronous file upload becomes simple. (The form was previously submitted to the IFRAME for implementation) 1: Get File object 2: Read ...

  • 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.