问题描述
||
好的,我明白了,此刻,我只打印提交的第一个图像!我该怎么做才能不受限制,以便我的foreach可以插入所有这些?
<table width=\"400\">
<form action=\"\" method=\"post\" enctype=\"multipart/form-data\" >
<p>Pictures:
<input type=\"file\" name=\"pictures[]\" />
<input type=\"file\" name=\"pictures[]\" />
<input type=\"submit\" value=\"Send\" />
<input type=\"hidden\" value=\"<?PHP echo $row_Rs_maxID [\'MAX(projectos_ID)\']; ?>\" name=\"idz\" id=\"idz\" />
</p>
</form>
<?PHP
foreach ($_FILES[\"pictures\"][\"error\"] as $key => $error) {
if ($error == UPLOAD_ERR_OK) {
$tmp_name = $_FILES[\"pictures\"][\"tmp_name\"][$key];
$name = $_FILES[\"pictures\"][\"name\"][$key];
move_uploaded_file($tmp_name,\"uploads/$name\");
}
}
foreach($_FILES as $file)
{
#upload deu certo
$query = MysqL_query(\"INSERT INTO projectoimagens (projecto_fk,image)
VALUES (,\'\".$_FILES[\"pictures\"][\"name\"][$key].\"\')\");
}
?>
解决方法
你的问题措辞很尴尬。不确定这是否是您要的:
mysql_connect(\'localhost\',\'user\',\'pass\') or trigger_error(\'Unable to connect to MySQL: \' . mysql_error());
mysql_select_db(\'database_name\') or trigger_error(\'Unable to select DB: \' . mysql_error());
foreach ($_FILES[\"pictures\"][\"error\"] as $key => $error) {
if ($error == UPLOAD_ERR_OK) {
$tmp_name = $_FILES[\"pictures\"][\"tmp_name\"][$key];
$name = $_FILES[\"pictures\"][\"name\"][$key];
move_uploaded_file($tmp_name,\"uploads/$name\");
mysql_query(\"INSERT INTO table_name (col1,col2,col3) VALUES(\'something\',\'somethingelse\',\'uploads/\" . mysql_real_escape_string($name) . \"\');\") or trigger_error(\'Unable to INsert: \' . mysql_error());
}
}
?>
那可能就是您想要的。您将不得不对其进行大量修改以匹配您的数据库信息,但是希望可以将您带到您想要去的地方。