code example of how to implement asynchronous file upload via Ajax in PHP _php tutorial

Source: Internet
Author: User
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)
Copy CodeThe code is as follows:

<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 true techarticle 1: Get File object 2: Read 2 binary Data 3: Simulate HTTP request, send data out (usually troublesome here) send using Sendasbinary method of XMLHttpRequest object under Forefox ...

  • Related Article

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