Code example for asynchronous file upload using Ajax in php

Source: Internet
Author: User
With the support of filefilereader, how to implement asynchronous file upload in php with Ajax technology makes asynchronous file Upload easier. (Previously, the form will be submitted to iframe for implementation) Ajax

1: Get the file object
2: read binary data
3: simulate http requests and send data (this is usually troublesome)
Use the sendasbinary method of the xmlhttprequest object to send data under forefox;
4: Perfect Implementation
Problems encountered
Currently, only firefox can correctly upload files. (Chrome can also be uploaded using google. gears)
The file data read from firefox and chrome is different (I don't know if it is the reason for the debugging tool)
Chrome and other advanced browsers do not have the sendasbinary method and can only use the send method to send data. it may be because the above causes the upload to fail correctly. (Normal text files can be uploaded correctly after testing)
The code is as follows:




Html5 file and filereader





(Drag the image here) get the file base64 encoding using filereader







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.