How to change filelist file

I have this input type "file" and I want to change its list of files . Example:

 <input type = "file" id = "fileinput" /> <script type = "text/javascript> document.getElementById("fileinput").files = [10]; </script> 

The problem is that the fileinput element files list is not set. How to do it?

+7
source share
2 answers

For security reasons, browsers do not allow javascript to modify the files that will be downloaded: only the user can select files through the user interface. This is done to prevent the evil script from loading /etc/passwd , for example, without the knowledge of the user.

The only exception is that calling β€œreset” on the form will clear the file or list of files, but you can never add them programmatically.

+14
source

You want to use the multiple attribute in the input element. Thus, in new browsers, the user will be able to select several files to download.

-one
source

All Articles