I have a form where through the Bootstrap modal, it uploads automatically. It is working properly, the problem is that it is not cleaning the field. See:
<form method="post" id="form-upload" novalidate enctype="multipart/form-data">
<label for="email" style="font-weight: normal"><strong>Formato permitido:</strong> JPG, JPEG e PNG<br><strong>Tamanho da imagem:</strong> 1170 x 300</label>
<div class="md-group-add-on">
<span class="md-add-on-file">
<button class="btn btn-primary waves-effect waves-light">Foto</button>
</span>
<div class="md-input-file">
<input type="file" id="fotoCapa" name="FotoCapa"/>
<input type="text" class="md-form-control md-form-file">
<label class="md-label-file"></label>
</div>
</div>
<div id="sucesso"></div>
</form>
<script type="text/javascript">
$(function(){
$('#fotoCapa').change(function(e) {
e.preventDefault();
var formData = new FormData();
formData.append('FotoCapa', $('#fotoCapa').prop('files')[0]);
$.ajax({
url: 'alterar-foto-capa.php',
data: formData,
type: 'post',
success: function(response){
var status = JSON.parse(response);
if(status.Status === 0){
$('#sucesso').html("<div class='alert alert-success'>A foto foi alterada com sucesso!</div>");
$('#fotoCapa').val("");
}else{
$('#sucesso').html("<div class='alert alert-danger'>" + status.Status + "</div>");
}
console.log(response);
},
processData: false,
cache: false,
contentType: false
});
});
});
</script>