havent tackled file upload before but having an initial issue.
I already have a form that updates user preferences (email and a few tick boxes for options).
This works perfectly fine but am now adding profile images into the form.
The form looks like so:
<form class="updatepref" method="post" enctype="multipart/form-data">
<input type="email" name="email">
<input type="file" name="upfile">
<input type="submit" class="update" Value="Save Settings">
</form>
I am posting this data via ajax:
$('.updatepref').submit(function(){
$.ajax({
type: "POST",
url: "../process/updateuserpref.php",
data: $('.updatepref').serialize(),
dataType: "json",
success: function(response){
}
});
return false;
});
And then the start of the PHP page for the file upload is:
// Undefined | Multiple Files | $_FILES Corruption Attack
// If this request falls under any of them, treat it invalid.
if (
!isset($_FILES['upfile']['error']) ||
is_array($_FILES['upfile']['error'])
) {
throw new RuntimeException('Invalid parameters.');
}
No matter what, i always get the 'Invalid Parameters' error message.
Whats going on? Can ajax serialise file upload?
When i check in the parametres sent (using firebug) it only show the email and any tick boxes etc. The file is not posted.