I would like to ask how to validate multiple file input using the jQuery validation-plugin.
Currently I have these codes but it doesn't work:
.html:
<form id="uploadPhotoForm" enctype="multipart/form-data" method="POST">
<table class= "uploadPhotoTable">
<tr>
<td>Photo</td>
<td>:</td>
<td><input class="field" type="file" name="files[]" id="upload_photo" align='right' multiple /></td>
</tr>
</table>
</form>
.js:
$('#uploadPhotoForm').validate({
rules: {
files: {
required: true,
extension: "png"
}
},
messages:{
files:{
required : "Please upload atleast 1 photo",
extension:"Only png file is allowed!"
}
}
});
I also will use this code to post to new PHP for processing. But it seems like in my uploadPhoto.php, $_FILES['files']['tmp_name']
is undefined. May i know how to solve this?
if ($('#uploadPhotoForm').valid()) {
$.ajax({
url: "inc/uploadPhoto.php",
type: "POST",
data: new FormData(this),
contentType: false,
cache: false,
processData:false,
success: function(data){
$("#error1").html(data);
}
});
}