我想從一個輸入上傳兩個文件,兩個文件都出現在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