The error in the code is that when I click the "Add" new input file button, the intention is to add only one field after the last, but the button triples.
My HTML code looks like this:
<div class="col-md-8">
<div class="form-group input-files">
<input type="file" name="imagem_file[]" class="form-control">
</div>
<div class="form-group input-files">
<input type="file" name="imagem_file[]" class="form-control">
</div>
<div class="form-group input-files">
<input type="file" name="imagem_file[]" class="form-control">
</div>
</div>
And the button for the action:
<button onClick="addInput();" class="btn btn-sm btn-info">[+]</button>
The javascript looks like this:
<script>
function addInput(){
$(".input-files").after('<div class="form-group input-files"><input type="file" name="imagem_file[]" class="form-control"></div>');
}
</script>
If you leave only one input file field, it generates another, but from there it multiplies by the amount being generated.
The example in Codepen.io .