Created
December 9, 2013 05:59
-
-
Save joshbeckman/7867926 to your computer and use it in GitHub Desktop.
Handle and get information about files selected.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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