Skip to content

Instantly share code, notes, and snippets.

@joshbeckman
Created December 9, 2013 05:59
Show Gist options
  • Save joshbeckman/7867926 to your computer and use it in GitHub Desktop.
Save joshbeckman/7867926 to your computer and use it in GitHub Desktop.
Handle and get information about files selected.
if (window.File && window.FileReader && window.FileList && window.Blob) {
// Great success!
function handleFileSelect(evt) {
var files = evt.target.files;
// files is a FileList (object) of File objects. List some properties.
var output = [];
for (var i = 0, f; f = files[i]; i++) {
output.push('<li><strong>', escape(f.name), '</strong> (', f.type || 'n/a', ') - ',
f.size, ' bytes, last modified: ',
f.lastModifiedDate ? f.lastModifiedDate.toLocaleDateString() : 'n/a',
'</li>');
}
document.getElementById('div').innerHTML = '<ul>' + output.join('') + '</ul>';
}
document.getElementById('fileGetter').addEventListener('change', handleFileSelect, false);
} else {
alert('The File APIs are not fully supported in this browser.');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment