我对此非常陌生,并且很难为构建图像上传创建一个非常简单的脚本。
我有一个名为txtfoto
的输入文件,如果我插入单个记录这很好用,但我想要做的是一次插入名为txtfoto[]
的4个输入文件的值。我确信我的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));}
}
答案 0 :(得分:1)
for ($key=0; $key<count($_FILES["txtfoto"]["name"]); $key++){
$file = $_FILES["txtfoto"]["name"][$key];
$sql = "INSERT INTO imagenes (nombre,foto) VALUES (:nombre,:foto)";
$result = $db->prepare($sql);
$result->execute(array(':nombre' => $txtnombre, ':foto' => $file));}