我在使用PHP中的数组插入多个文件时遇到了麻烦。
$applications=$_FILES['applications']['name'];
for($i = 0; $i < count($applications); $i++)
{
$tmp_name=$_FILES['applications']['tmp_name'][$i];
move_uploaded_file($tmp_name, "ujuri_admin/uploads/applications/$applications[$i]");
}
$send_data="INSERT INTO table (application[],date_now) VALUES ('$applications[$i]', NOW())";
答案 0 :(得分:0)
您必须使用当前正确的for
值在$applications[$i]
循环内运行查询。您的代码应如下所示:
$stmt = $db->prepare('INSERT INTO table (application, date_now) VALUES (?, NOW())');
for($i = 0; $i < count($applications); $i++)
{
$tmp_name=$_FILES['applications']['tmp_name'][$i];
move_uploaded_file($tmp_name, "ujuri_admin/uploads/applications/$applications[$i]");
$stmt->execute(array($applications[$i]));
}
$stmt->close();
(假设$db
是PDO个实例)