Posted By

yingyi on 07/29/11


Tagged

javascript html5


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

abhishekgoel137


Get multiple file information without uploading


 / Published in: JavaScript
 

  1. <input type="file" multiple id="files" name="files[]"/><br/>
  2.  
  3. <h3>Output</h3>
  4. <output id="list"></output>
  5.  
  6. <script>
  7. function handleFileSelect(evt) {
  8. var files = evt.target.files; // FileList object
  9. // files is a FileList of File objects. List some properties.
  10. var output = [];
  11. for (var i = 0, f; f = files[i]; i++) {
  12. output.push('<li><strong>', f.name, '</strong> (', f.type || 'n/a', ') - ',
  13. f.size, ' bytes, last modified: ',
  14. f.lastModifiedDate.toLocaleDateString(), '</li>');
  15. }
  16. document.getElementById('list').innerHTML = '<ul>' + output.join('') + '</ul>';
  17. }
  18.  
  19. document.getElementById('files').addEventListener('change', handleFileSelect, false);
  20.  
  21. </script>

Report this snippet  

You need to login to post a comment.