Processing XHR2 file uploads in PHP
Google Developers Logo

Missed the Chrome Developer Summit?

All sessions available on demand - Watch Now

My article “New Tricks in XMLHttpRequest2” has many fine examples, but what it doesn’t have is any server code to illustrate how to handle files. If you’re curious how to process a file upload using xhr.send(FormData), here’s a quick example of an image upload in PHP.

This server is trivial but it demonstrates two things. The first is sending a file and extra payload at the same time. The second is how to grab the file (and other data) in PHP. Lastly, the image is encoded into a data: URL and included in a JSON response sent back to the client.

Note: the sample has been removed.

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 3.0 License, and code samples are licensed under the Apache 2.0 License. For details, see our Terms of Service.