"have the" files "property in JavaScript? Consider this HTML snippet: <\/script>')

Why does "HTML <input type = 'file' /"> "have the" files "property in JavaScript?

Consider this HTML snippet:

<input type='file' id='fileUpload' />

To access this control in JavaScript, we can write:

var temp = document.getElementById('fileUpload');

Well, don't be angry, I know you all know that. But the interesting part is that the variable tempnow has a property called files(not a file , but files , plural form), which has a type FileList, which, of course, is a list of objects File. This semantically should mean that downloading multiple files with one and only one control of loading HTML files should be possible. However, you cannot upload multiple files this way, and there are many workarounds, not direct use.

How do you explain this paradox?

Update: I built this jsfiddle to see one of the answers in action.

+5
3

Gecko DOM, drag-n-drop.

+2

:

https://developer.mozilla.org/en/Using_files_from_web_applications

This is possible in Firefox since version 3.0. At that time, I wrote an extensive article on how to make real Ajax file downloads: http://igstan.ro/posts/2009-01-11-ajax-file-upload-with-pure-javascript.html

Firefox 3.0 API is currently uninstalled. Instead, you should use FileReaderwith FormData. This should work in the latest browser. I have not done extensive research, but I believe that no version of IE has yet been implemented.

+1
source

All Articles