gpt4 book ai didi

javascript - 使用表单提交上传具有相同字段名称的多个文档

转载 作者:可可西里 更新时间:2023-11-01 13:02:31 26 4
gpt4 key购买 nike

我想使用 html 中的表单提交上传具有相同字段名称的多个文档(PDF、doc、txt 等...)。我已经用 PHP 5 File Upload 尝试了一切来自 w3schools.com。

<form action="upload.php" method="POST">
<div class="left">
<h2>Detail 1</h2>
Name:<input type="text" name="txtName[]"><br>
Card No:<input type="text" name="txtCardNo[]"><br>
Date of Birth:<input type="text" name="txtBdate[]"><br>
Document:<input type="file" name="docs[]"><br>
</div>
<div class="left">
<h2>Detail 2</h2>
Name:<input type="text" name="txtName[]"><br>
Card No:<input type="text" name="txtCardNo[]"><br>
Date of Birth:<input type="text" name="txtBdate[]"><br>
Document:<input type="file" name="docs[]"><br>
</div>
<div class="left">
<h2>Detail 3</h2>
Name:<input type="text" name="txtName[]"><br>
Card No:<input type="text" name="txtCardNo[]"><br>
Date of Birth:<input type="text" name="txtBdate[]"><br>
Document:<input type="file" name="docs[]"><br>
</div>
<div class="clear"></div>
<input type="submit" value="Submit">
</form>

但我不知道如何将这些多个文档传递到表单提交功能中。我在 This jsFiddle 中写了上面相同的代码并且需要使用 javascript 提交。

谢谢

最佳答案

您可以使用带有循环的 php 函数上传多个文件以计算总文件和数据,如下所示(Codeigniter 插入)

    if(!empty($_POST['txtName'])){              
for($i=0; $i<count($_POST['txtName']); $i++){
$cont['name'] = $_POST['txtName'][$i];
$cont['cardno'] = $_POST['txtCardNo'][$i];
$cont['dob'] = $_POST['txtBdate'][$i];
$cont['docs'] = str_replace(' ', '_',$_FILES['docs']['name'][$i]);

if($cont['docs'] != "")
{
move_uploaded_file($_FILES["docs"]["tmp_name"][$i], $target_path.$cont['docs']);

}
$this->db->insert('detail',$cont);

}
return true;
}else{
return false;
}

关于javascript - 使用表单提交上传具有相同字段名称的多个文档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37346444/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com