My upload form isn't working for some reason, when I submit the form the PHP file runs and my $_FILES variable is empty. I've been stuck for hours and I feel like I've been through every post on this site and I just don't understand what's going wrong.
HTML
<form id="uploadform" name="uploadform" method="POST" enctype="multipart/form-data">
<input id="realupload" name="realupload" type="file" multiple/>
<input id="uploadsubmit" type="submit" value="upload"/>
</form>
JQuery
$('#uploadsubmit').click(function(e)
{
e.preventDefault();
$.ajax({
type: "POST",
url: "upload.php",
data: function(){
alert("test");
var data = new FormData();
data.append("realupload", jQuery("#realupload").get(0).files[0]);
return data;
}
,
processData:false,
contentType: false,
cache: false,
success: function(theData){
$('#innercontent').html(theData);
},
error: function() {
$('#innercontent').html("ERROR, HELP");
}
});
}
});
PHP (upload.php)
<?php
//upload.php
if (isset($_FILES["realupload"]))
{
echo "SUCCESSFUL UPLOAD " . $_FILES["realupload"]["error"];
}
else{
echo "FILES NOT SET";
}
?>
- The PHP file is just a test file to check if the upload worked
- FILES NOT SET is output every time
- The alert inside of the ajax data function doesn't run, I'm not sure if it's should be
- Trying to create a multiple file uploader
Could this be to do with the server? There is already a forum uploaded on there that in itself allows uploads, so I don't think that that is the case, but I'm not sure.
Thanks!
Edit: Guys, thanks for the links, but you can now upload files with HTML5 and the XmlHttpRequest2 object and I'm trying to figure that out.