gpt4 book ai didi

javascript - php jquery 克隆输入字段插入同一列中的数据库

转载 作者:行者123 更新时间:2023-11-29 02:15:41 25 4
gpt4 key购买 nike

我正在创建一个表单。

表单中有几种字段类型。

其中我有一个可以填充的文件上传框。

用户可以在文件上传输入中附加多个文件。

On submitting the file names should be saved in db in same column separated by commas.

对于单个文件,我知道该怎么做,但是因为它是克隆的,所以我很困惑

<span class="button btn-primary"> Choose File </span>
<input type="file" class="gui-file required" name="docs[]" onChange="document.getElementById('orderupload1').value = this.value;">
<input type="text" class="gui-input" name="orderupload1" id="orderupload1" placeholder="Attach Domcuments Here..." readonly>

表单和字段填充与上述代码和一些 JS 配合使用效果很好。

现在的问题是如何在同一列中插入以逗号分隔的每个填充字段文件名。

我已经为单个字段做了如下操作:

$docs=$_FILES['docs[]']['name'];

$temp_doc_name=$_FILES['docs[$i]']['tmp_name'];

if($docs!=''){


if ($temp_doc_name != ""){

$newFilePath1 = "uploadFiles/" . $docs;


if(move_uploaded_file($temp_doc_name, $newFilePath1)) {


}
}
}

$sql = "insert into students (documents) values(LAST_INSERT_ID(), '$docs')";

最佳答案

用 foreach 替换您的代码,如下所示。

foreach ($_FILES['docs']['name'] as $key => $val) {
if (move_uploaded_file($_FILES['docs']['tmp_name'][$key], $newFilePath1)) {
/* FILE IS UPLOADED SUCCESSFULLY */
}
}

关于javascript - php jquery 克隆输入字段插入同一列中的数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40235922/

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