Skip to content

Instantly share code, notes, and snippets.

@apueee
Forked from ajaxray/upload.js
Created June 28, 2013 16:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save apueee/5886202 to your computer and use it in GitHub Desktop.
Save apueee/5886202 to your computer and use it in GitHub Desktop.
(function () {
var input = document.getElementById("image"), formdata = false;
if (window.FormData) {
formdata = new FormData();
}
input.addEventListener("change", function (evt) {
file = this.files[0];
if (!!file.type.match(/image.*/)) {
if ( window.FileReader ) {
reader = new FileReader();
reader.onloadend = function (e) {
//showUploadedItem(e.target.result, file.fileName);
};
reader.readAsDataURL(file);
}
if (formdata) {
formdata.append("image", file);
}
}
if (formdata) {
$.ajax({
url: "upload.php",
type: "POST",
data: formdata,
processData: false,
contentType: false,
success: function (res) {
window.uploadedImage = res;
$('#image-holder').append('<img src="' + window.uploadedImage + '" />');
}
});
}
}, false);
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment