Storing filenames of multiple uploaded files into a MySQL database
Okay I get to this and at this momento I'm printing only the 1st imagem that is submited! How can I do to be unlimiteed so my foreach can INSERT all of them ?
<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_I开发者_开发问答D)']; ?>" 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]."')");
}
?>
Your question is worded very awkward. Not sure if this is what you are after:
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());
}
}
?>
That might be what you are looking for. You will have to modify it extensively to match your database information, but hopefully that gets you to where you are wanting to go.
精彩评论