Upload Multiple Images and Store in Database using PHP and MySQL
Now, In this blog post we focused on Multiple Image uploading functionality using PHP.
Now, In this blog post we focused on Multiple Image uploading functionality using PHP.
Step 1) Add HTML:
<form role=”form” name=”” method=”post” enctype=”multipart/form-data” action=”image-upload-do.php”>
<div class=”form-group”>
<label>Gallery Image</label>
<input required name=”image[]” multiple type=”file” class=”form-control”>
</div>
<button type=”submit” class=”btn btn-success btn-sm”>Submit </button>
</form>
Step 2) Create Database :
create database image_upload;
Step 3) Create Table :
create table image(id int primary key AUTO_INCREMENT,img_ext varchar(6));
Step 4) Upload Multiple Files in PHP (image-upload-do.php)
$db = new PDO(mysql:host=localhost;dbname=image_upload;charset=utf8mb4, root, ); //database connection
foreach($_FILES[image][tmp_name] as $key => $tmp_name) {
$img_ext = pathinfo($file_name, PATHINFO_EXTENSION);
$q = $db-> query(“insert into image(img_ext) values($img_ext)”) or die(“error”);
$lastID = $db-> lastInsertId();
$imageNewName = $lastID.”.”.$img_ext; move_uploaded_file($file_tmp, “image/”.$imageNewName);
}
ohhh your study mysql but hacked your website by systemdenied