I'm trying to upload images via AJAX and PHP, but to no avail. I've reviewed, updated, anyway, codes hit all the other codes I searched, I really do not understand.
HTML:
<form class="photo_change" method="post" enctype="multipart/form-data">
<input class="arquivo" name="img" type="file" />
<input type="submit" class="img_envia" name="envia_img" value="SELECIONAR IMAGEM" />
<img style="display: none; width:22px; height: 22px; margin-left:10px;" src="/img/loader.gif" /> </form>
Jquery:
$('.img_envia').click(function(){
$('.arquivo').trigger('click');
return false;
});
$('.arquivo').change(function() {
var fileName = $(this)[0].files[0].name;
var formData = new FormData($('.photo_change'));
$('#modal_photo_content form img').show();
$.ajax({
url:'http://localhost/photo_change.php',
type: 'POST',
data: formData,
processData: false,
contentType: false,
success: function(data){
console.log(data);
$('.img_envia').removeAttr('disabled','disabled');
},
error: function() {
$('.img_envia').removeAttr('disabled','disabled');
alert("ERRO: Tente novamente mais tarde.");
}
});
});
And in PHP I'm giving a var_dump in the $ _FILES variable and $ _POST to see if I'm getting something, but the return is always that of the photo: