Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display selected file names before uploading multiple files in Struts2?

Tags:

I am using Struts2 to upload multiple files:

<s:file name="files" multiple="multiple" /> 

When I select multiple files it displays the number of files, eg. 3 files.

The project requirements are that the user should be able to see what files he selected before uploading.

Is it possible to display the selected files names in a list or maybe in the control itself ?

like image 428
Pradnya Avatar asked Sep 28 '14 07:09

Pradnya


People also ask

How do you append files in input type file multiple before uploading?

You could add a new <input type="file"> whenever you finished uploading the previous files and hide the previous input. This way you keep adding a new input every time you want to add more files and prevent the previous input from being overwritten.


1 Answers

You can use the HTML5 files property of the <input type="file" /> element like follows:

updateList = function() {      var input = document.getElementById('file');      var output = document.getElementById('fileList');      var children = "";      for (var i = 0; i < input.files.length; ++i) {          children += '<li>' + input.files.item(i).name + '</li>';      }      output.innerHTML = '<ul>'+children+'</ul>';  }
<input type="file" multiple         name="file"            id="file"      onchange="javascript:updateList()" />    <p>Selected files:</p>    <div id="fileList"></div>
like image 122
Andrea Ligios Avatar answered Sep 29 '22 09:09

Andrea Ligios