I would like to ask how to validate multiple input files using the jQuery validation plugin.
I currently have these codes, but it does not 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 will also use this code to publish to new PHP for processing. But it looks like there is undefined in my uploadPhoto.php, $_FILES['files']['tmp_name'] . Can I find out 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); } }); }
source share