I want to do a form which allows to upload a file through a JQuery submit. I have this html code:
<form method="post" id="addPhotoForm" enctype="multipart/form-data">
<input type="hidden" name="MAX_FILE_SIZE" value="10000000">
<input type="file" name="photo" />
<input type="text" name="words" />
<input type="button" onclick="go();" />
</form>
go();
allows to submit (JS / JQuery) :
function go() {
$.post('processing.php', $("#addPhotoForm").serialize()).done(function (data) {
console.log(data);
});
}
and PHP code:
var_dump($_POST['words']);
var_dump($_FILES);
die('');
Here, $_POST['words']
displays the right thing but $_FILES
stays an empty array even after selecting a file. Where is the problem please?
Thanks a lot.