I have this HTML:
<form action='uploadhandle.php' method='POST' enctype="multipart/form-data">
<input type='file' class='fileinput' id='photo1' name='photo1'>
<input type='button' id='upload1' name='upload1' value='Upload'>
</form>
My jquery code is:
$('#upload1').click(function(){
$.ajax({
url: "uploadhandle.php",
data: 'photo1='+photo1,
success: function(data){$('#result_div').html(data)}
});
In my uploadhandle.php, when I try to display the $_POST[‘photo1’], nothing comes up, it’s “undefined”.
Does anyone know what I did wrong?
Thanks a lot,
Regards
You cannot upload a file via AJAX. It isn’t possible.
What IS possible is using a plugin or another method that “simulates” ajax by creating an iframe and submitting the info in the background. There are several plugins that handle this, some are very complex, some simply extend the ajax function itself.
That being said, your syntax server side is also wrong. You have to deal with
$_FILESnot$_POSTto find and use the submitted file.Good luck.