Reputation: 133
I'm pretty new at this and getting a hard time building a very simple script for image upload.
I have a input file called txtfoto
if I insert a single record this works great, but what I trying to do is insert the values of 4 input files called txtfoto[]
at once. I'm sure that something is wrong or missing in my PHP
code so any help i'll great.
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 sentence:
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));}
}
Upvotes: 1
Views: 1374
Reputation: 2509
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));}
Upvotes: 1