我想从一个输入上传两个文件,两个文件都出现在uploads文件夹中,因为它们应该这样做,但只有一个文件路径进入数据库。上传文件路径到数据库
E.g.如果我上传test1.pdf和test2.pdf,它们都将进入上传文件夹,但test1.pdf将被插入数据库的两列而不是一列。
在我疯了之前,有谁能帮助我吗?
if (count($_FILES['field2']['name']) >= 1) {
//Loop through each file
for ($i = 0; $i < count($_FILES['field2']['name']); $i++) {
//Get the temp file path
$tmpFilePath = $_FILES['field2']['tmp_name'][$i];
//Make sure we have a filepath
if ($tmpFilePath != "") {
//save the filename
$shortname = $_FILES['field2']['name'][$i];
//save the url and the file
$filePath = "uploads/" . date('d-m-Y-H-i-s') . '-' . $_FILES['field2']['name'][$i];
$filePath1 = "uploads/" . date('d-m-Y-H-i-s') . '-' . $_FILES['field2']['name'][$i];
//Upload the file into the temp dir
if (move_uploaded_file($tmpFilePath, $filePath)) {
$sql = "INSERT INTO " . $config_tbl_prefix . " subcontractor_qs (field1, field2)
VALUES
('$filePath','$filePath1')";
mysql_query($sql);
}
}
}
}
}
为什么你使用的是mysql *函数,它在PHP的新版本中被弃用,并在PHP7中被删除。 –
你需要一个循环。 – Script47
@RossH如果你不在乎,为什么你还在发展? – Script47