我正在创建一个表单。
表单中有多种字段类型。
其中我有一个可以填充的文件上传框。
用户可以在文件上传输入上附加多个文档。
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/