I am uploading multiple images via the code below (it works), but I can't insert these images' urls into my database. I tried a few thing but can't make it work. My code is inn't completed yet, so I didn't add controls (filetype, filesize, etc) yet.
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); // getting the extension
// creating a unique value here
$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; // it echoes image urls, so everything is okay so far.
}
} else {
echo "Failed";
}
I used the query below in a foreach loop after echo $makeaname; but it didn't work. I appreciate any kind of help or guidance.
$upload_image = $sqli->prepare("INSERT INTO images(image_value, type, size) VALUES (?,?,?)");
$upload_image->bind_param("sss", $makeaname, $_FILES['images']['type'], $_FILES['images']['size']);
$upload_image->execute();
$_FILES['images']['type']correct in your bind statement?` In other words, should it be$_FILES['images']['type'][$key]?