2
I have a field to upload PDF documents, when attaching a document appears the PDF icon, but I am using multiple upload and only an icon appears when ideally it would appear an icon for each attached file, I know it’s possible but I don’t have much knowledge of Js, someone could help?
Code: HTML
<label id="timg" for="upload-photo">Upload <i class="fa fa-folder-open" aria-
hidden="true"></i></label>
<input type="file" multiple id="upload-photo" required accept=".pdf, application/pdf">
<div id="thumbs">
<img src="" id="pdfimg" style="display: block; width: 50px; height: 50px;"/> </div>
JS
const icons = {
'application/pdf': 'http://iconbug.com/data/5b/507/52ff0e80b07d28b590bbc4b30befde52.png',
}
const input = document.querySelector('#upload-photo');
const image = document.querySelector('#pdfimg'); //Script PDF MultipleUpload
input.addEventListener('change', function() {
const tipo = this.files[0].type;
image.src = icons[tipo];
});
Thank you very much friend, everything worked out, only one more question is possible to show the name of the file under the image, when attached?
– HBretone
@Henriquebretone Yes, I edited the answer, I added a
span
with the name (this.files[i].name
) right after the image =)– Mathiasfc
Thanks even guy saved my serious life.
– HBretone