我想问一下如何使用jQuery validation-plugin验证多个文件输入.
目前我有这些代码,但它不起作用:
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>
Run Code Online (Sandbox Code Playgroud)
.js文件:
$('#uploadPhotoForm').validate({
rules: {
files: {
required: true,
extension: "png"
}
},
messages:{
files:{
required : "Please upload atleast 1 photo",
extension:"Only png file is allowed!"
}
}
});
Run Code Online (Sandbox Code Playgroud)
我还将使用此代码发布到新的PHP进行处理.但似乎在我的uploadPhoto.php中,$_FILES['files']['tmp_name']是未定义的.我可以知道如何解决这个问题吗?
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);
}
});
}
Run Code Online (Sandbox Code Playgroud)