Clone input type file with jQuery
Answer to: https://pt.stackoverflow.com/q/362954/45707
by Emanuel Poletto
HTML
<form id="formExemplo" action="" method="post" enctype="multipart/form-data">
<input type="file" name="imagem" id="imagem" multiple="multiple">
</form>
JavaScript
$('#imagem').on('change', function() {
if ($(this).val()) {
let form = $('#formExemplo'),
newFile = $(this).clone(),
newName = 'imagem' + form.find('[name="imagem"]').length;
newFile.removeAttr('id')
.attr('name', newName)
//.css('display', 'none');
$('#formExemplo').append(newFile);
$(this).val('');
}
});