选择多个文件以按html表中的填充进行上传

时间:2020-03-01 18:10:55

标签: javascript php jquery html ajax

我想找到所选文件的编号,因为文件选择标记在HTML表的每一行中都带有一个按钮。 我只想在单击同一行按钮并上载所有选定的文件时找出文件总数(选定的文件总数)

以下代码给出错误。

“未捕获的TypeError:无法读取未定义的属性'length'”

function saveValue(data) {
  var fileU = $(data).closest('tr').find('input[type=file]');
  var count = files.length;
  console.log(count);
  for (var i = 0; i < count; i++) {
    var file = fileU[i].files[0];
    console.log(file)
    formData.append("files[]", file);
  }
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<table>
  <tr>
    <td width="10%" align="center" bgcolor="">
      <p data-placement="top" data-toggle="tooltip" title="Attached Letter"><input type="file" class='files' name="files[]" multiple></p>
    </td>
    <td width="40%"><button class="btnSelect" onclick='saveValue(this);'> Count </button></td>
  </tr>
</table>

1 个答案:

答案 0 :(得分:0)

此行引发错误

def files_to_dict(folder_name):
    list_of_files = os.listdir("./"+folder_name) #read file names of current dir in list
    newDict=dict()
    for year in (list_of_files):
        if(year!=".ipynb_checkpoints"):
            ofile = open("./"+folder_name+"/"+year,"r")
            data = ofile.read().split(',')

    return data

var count = files.length; 意味着变量"Uncaught TypeError: Cannot read property 'length' of undefined"并未在任何地方定义。

尝试定义它,例如:

files