0

我正在尝试根据How to upload multiple files using PHP, jQuery and AJAX中的想法在不使用任何 jquery 插件的情况下上传文件。现在我的多个文件的 html 部分是这样的。

<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>

我的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;
});

在 process.php.I 中检查。$_POST['file'] and $_POST['other_inputfields']它给了我空字符串

4

0 回答 0