I am trying to upload images to database using prepared statement. Whenever I execute the query the fields name and id are inserted correctly in database as expected except the images I am getting 0 bytes in database. I tried uploading multiple images using move_uploaded_file()
and it worked but it just didn't with database I tried uploading an image of only size 10kb and didn't work. its keep giving me 0 byte in database.
here is my code
//uploading image to database
function upload_image($last_id, $conn)
{
$extension = [
"jpeg",
"jpg",
"png",
"gif",
];
if (isset($_POST["submit"])) {
//in case of uploading multiple images
foreach ($_FILES["input"]["tmp_name"] as $key => $tmp_name) {
$name = basename($_FILES["input"]["name"][$key]);
$imageFileType = pathinfo($name, PATHINFO_EXTENSION);
if (in_array($imageFileType, $extension)) {
$stmt3 = $conn->prepare("INSERT INTO image (id ,name, image) VALUES (?, ?, ?)");
$image = addslashes(file_get_contents($_FILES["input"]["tmp_name"][$key]));
$stmt3->bind_param("isb", $last_id, $name, $image);
$stmt3->execute();
$stmt3->close();
}
}//end loop
}//end if
}//end function
there is no need to put the html code of the form since it already worked with move_uploaded_file()