1
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 code of the page
<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;
Upshot: Undefined index: user-profile
Possible duplicate of Upload only with jQuery.ajax and PHP
– Woss
Related: Error sending Upload with Ajax
– Woss
Related: Upload a file with AJAX
– Woss