【发布时间】:2014-12-21 16:16:34
【问题描述】:
我对此很陌生,很难构建一个非常简单的图片上传脚本。
我有一个名为txtfoto 的输入文件,如果我插入一条记录,这很好用,但我想做的是一次插入4 个名为txtfoto[] 的输入文件的值。我确定我的 PHP 代码中存在错误或缺失,所以任何帮助我都会很好。
HTML:
<label>Imagen: <input name="txtfoto[]" type="file">
<input name="txtfoto[]" type="file">
<input name="txtfoto[]" type="file">
<input name="txtfoto[]" type="file"></label>
PHP:
$file = $_FILES["txtfoto"]["name"][$key]
mysql语句:
for ($key=0; $key<count($_FILES["txtfoto"]["name"][$key]); $key++){
$sql = "INSERT INTO imagenes (nombre,foto) VALUES (:nombre,:foto)";
$result = $db->prepare($sql);
$result->execute(array(':nombre' => $txtnombre, ':foto' => $file));}
}
【问题讨论】:
-
你可以使用 for 循环来表示
for($key=0; $key<count($_FILES["txtfoto"]["name"][$key]); $key++) -
@Arif_suhail_123 谢谢!但仍然一次只插入一条记录。我需要一次插入 4 个 txtfoto[] 输入。
-
@Arif_suhail_123 是的。请再次检查我的代码。我添加了你的建议。