I'm trying to upload images with PHP and Ajax but the result says it's an undefined value
Javascript code
$('form[name="update-user"]').submit(function(){
form = $(this);
$.ajax({
url: 'switch/painel.php',
data: form.serialize() + '&acao=update_user',
type: 'POST',
beforeSend: function(){
form.find('.load').fadeIn('fast');
},
success: function(resp){
alert(resp);
},
complete: function(){
form.find('.load').fadeOut('fast')
}
});
return false;
});
Follow the page code
<form enctype="multipart/form-data" action="#" name="update-user" class="form-horizontal" accept="image/*" method="POST">
<input type="file" name="user-profile" id="file-profile">
<input type="submit" class="btn btn-success" value="Salvar dados">
</form>
Controller file
case 'update_user':
var_dump($_FILES['user-profile']);
break;
Result: undefined index: user-profile