By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,154 Members | 1,031 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,154 IT Pros & Developers. It's quick & easy.

input file-multi file, directory

P: n/a
For the <input type="file">, can I select directory? Multiple directories?


Jul 23 '05 #1
Share this Question
Share on Google+
2 Replies

P: n/a
"Quick Function" wrote
For the <input type="file">, can I select directory?
I 'm afraid not. You cannot even be sure of the existence of a particular
directory on other systems.
Multiple directories?

All at once??
Jul 23 '05 #2

P: n/a
Quick Function wrote:
For the <input type="file">, can I select directory? Multiple directories?



As mentioned, you can not select multiple files or directories using <input
type="file">. As a result, another solution is necessary. The following will
only work in the most modern of browsers (IE6SP1, Gecko-based browsers, Opera
7.53, perhaps others you will need to test):

<script type="text/javascript">
function anotherFile(lnk) {
if (document.createElement &&
lnk.insertBefore &&
lnk.parentNode) {

var finp = document.createElement('input');
var brk = document.createElement('br');
if (finp && brk) {
finp.type = 'file'; = 'file' + (new Date()).getTime() + Math.floor(100 *
lnk.parentNode.insertBefore(finp, lnk);
lnk.parentNode.insertBefore(brk, lnk);
return false;
<form name="myFormName" id="myFormId">
<input type="file" name="file1">
<a href="#" onclick="return anotherFile(this);">Another File</a>


- "(new Date()).getTime() + Math.floor(100 * Math.random())" is intended to
generate a unique form element name. This should not present much of a problem
on the server, most server-side technology has something like
Request.subkeys("file") that allows you to find all inputs that start with a
particular string. The other ways to do this is have a global variable that
gets incremented to produce "file2", "file3", etc.

- The code as written depends on the "Another File" link coming after the
<input>. This allows the use of insertBefore() to add another file input. The
other possibilities would be to have a dummy <span> under the last input as a
marker to insertBefore(), or simply appendChild() on the <form>.

- As already mentioned this only works in the most modern browsers.

- I haven't actually tested this to upload files. Some browsers may have a
problem actually submitting form inputs added to the form using

Grant Wagner <gw*****>
comp.lang.javascript FAQ -

Jul 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.