We are using <input type='file' multiple>
HTML to attach multiple attachments. It's showing 2 files if I upload 2 files; we need to show file names instead number.
How to Parse/Save the files using jQuery.
We are using <input type='file' multiple>
HTML to attach multiple attachments. It's showing 2 files if I upload 2 files; we need to show file names instead number.
How to Parse/Save the files using jQuery.
You can try something like this, then you can start playing with CSS to hide that input, etc...
$(function() {
const uploader = $('#uploader');
const list = $('#list');
$(uploader).on('change', function() {
const filesLength = uploader.get(0).files.length;
for (let i = 0; i < filesLength; i++) {
console.log(`File number ${i} has this name >> ${this.files[i].name}`);
list.append(`<li> ${this.files[i].name} </li>`)
}
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.0/jquery.min.js"></script>
<input
type="file"
multiple
name="file"
id="uploader"
/>
<div style="margin: 12px 0 0 0;">
<b>Uploaded files:</b>
<ul id="list"></ul>
</div>