Skip to content

Instantly share code, notes, and snippets.

@jacobtwlee
Last active January 15, 2017 15:12
Show Gist options
  • Save jacobtwlee/d17de16a0f3cbffe6435 to your computer and use it in GitHub Desktop.
Save jacobtwlee/d17de16a0f3cbffe6435 to your computer and use it in GitHub Desktop.
Handling file input
if (window.File && window.FileReader && window.FormData) {
var $inputField = $('#file');
$inputField.on('change', function (e) {
var file = e.target.files[0];
if (file) {
if (/^image\//i.test(file.type)) {
readFile(file);
} else {
alert('Not a valid image!');
}
}
});
} else {
alert("File upload is not supported!");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment