Hi,
I am uploading multiple images via the code below, but I don’t know how to insert these images into my MySQL database in bulk. Can you help me?
index.php
<form action="upload.php" method="post" enctype="multipart/form-data">
<div id="file_container">
<input name="images[]" multiple type="file" id="file[]"/><br/>
<input type="submit">
</div>
</form>
upload.php
$target = "upload/";
$test = 1;
foreach ($_FILES['images']['name'] as $key => $value) {
$path = $_FILES['images']['name'][$key];
$ext = pathinfo($path, PATHINFO_EXTENSION);
$name = md5($name);
$generate1 = md5(date('Y-m-d H:i:s:u'));
$randomizer = uniqid($name);
$name = $name . $generate1 . $randomizer;
$makeaname = $target . $name . "." . $ext;
if ($test == 1) {
if (move_uploaded_file($_FILES['images']['tmp_name'][$key], $makeaname)) {
echo "<strong>" . $value . "</strong> successful <br />\n";
echo $makeaname;
}
} else {
echo "Failed";
}
Generally I use a simple insert query like below but this time I THINK I need to use this query in a foreach in order to make itwork for x times, yet I can’t do it.
$upload_image = $sqli->prepare("INSERT INTO metadata_images(metadata_image_value, type, size) VALUES (?,?,?)"); $upload_image->bind_param("sss", $makeaname, $_FILES['images']['type'], $_FILES['images']['size']); $upload_image->execute();