I am trying to upload files without using any jquery plugin based on the idea from How to upload multiple files using PHP, jQuery and AJAX. Now my html portion for multiple files is like this.
<form method="post" name="addstudent" id="registrationform" enctype="multipart/form-data">
some input fields
<!--first file-->
<div class="file_div_child">
<input class="file" type="file" name="file[]" style="display: block;">
<button class="remove first_remove">X</button>
</div>
<!--second file-->
<div class="file_div_child">
<input class="file" type="file" name="file[]" style="display: block;">
<button class="remove first_remove">X</button>
</div>
-------so on
--also other input fields in form
<input type="submit" id="buttontext" class="student_registrationform_button" value="submit" />
</form>
My jquery:
$('#buttontext').click(function(){
formdata = false;
if (window.FormData) {
formdata = new FormData();
}
var i = 0, len = $(".file").length, img, reader, file;
$('.file').each(function() { var file = this.files[0];
if (window.FileReader) {
reader = new FileReader();
reader.readAsDataURL(file);
}
if (formdata) {
formdata.append("file", file);
}
});
$.ajax({
url: 'process.php',
type: 'POST',
data:formdata ,
success:function(data){ //alert(data);
console.log(data);return false;
});
In the process.php.I am checking $_POST['file'] and $_POST['other_inputfields']
.Its giving me null string