How to Upload Multiple Images in PHP 8 MySQL?

Jun 02, 2022



How to Upload Multiple Images in PHP 8 MySQL?

Hello Friends,

Today, I would like to show you how to upload multiple images in php 8 mysql?. We will look at example of Upload Multiple Images And Store In Database Using PHP 8 And MySQL. this example will help you Upload Multiple Images using PHP 8 & MySQL. I explained simply step by step Multiple image upload concept using php & mysql. you will do the following things for Multiple image upload concept using php 8 & mysql.

We will use get simple example of PHP 8 MySQL Multiple Image Upload Example

So, let's see bellow solution:


<!DOCTYPE html>

<html lang="en-US">


<meta charset="utf-8">

<meta name="viewport" content="width=device-width, initial-scale=1">

<title>how to upload multiple images in php 8 mysql?</title>

<link rel="stylesheet" href="">




$dbHost = "localhost";

$dbUsername = "root";

$dbPassword = "";

$dbName = "storage";

$db = new mysqli($dbHost, $dbUsername, $dbPassword, $dbName);

if ($db->connect_error) {

die("Connection failed: " . $db->connect_error);



$targetDir = "upload/";

$allowTypes = array('jpg','png','jpeg','gif');

$images_arr = array();

foreach($_FILES['images']['name'] as $key=>$val){

$image_name = $_FILES['images']['name'][$key];

$tmp_name = $_FILES['images']['tmp_name'][$key];

$size = $_FILES['images']['size'][$key];

$type = $_FILES['images']['type'][$key];

$error = $_FILES['images']['error'][$key];

$fileName = basename($_FILES['images']['name'][$key]);

$targetFilePath = $fileName;

$fileType = pathinfo($targetFilePath,PATHINFO_EXTENSION);

if(in_array($fileType, $allowTypes)){


$images_arr[] = $targetFilePath;

$insert = $db->query("INSERT into images (image_name) VALUES ('".$targetFilePath."')");


$count = $key + 1;

$success = " ".$count. " image file has been uploaded successfully.";


$statusMsg = "Failed to upload image";



$statusMsg = "Sorry, there was an error uploading your file.";



$statusMsg = 'Please Upload a Valid File';





<div class="container mt-5">

<div class="row">

<div class="col-md-12">

<div class="card w-75 m-auto">

<div class="card-header text-center bg-danger text-white">

<h3>how to upload multiple images in php 8 mysql? -</h3>


<div class="card-body">

<form action="" method="post" enctype="multipart/form-data">

<?php if(!empty($success)){ ?>

<p class="alert alert-success"><?php echo $success; ?></p>

<?php } ?>

<div class="form-group">

<div class="custom-file">

<label><strong>Select Images : <span class="text-danger">*</span></strong></label>

<input type="file" name="images[]" id="customFile" class="form-control" multiple required>


<?php if(!empty($statusMsg)){ ?>

<p class="text-danger"><?php echo $statusMsg; ?></p>

<?php } ?>


<div class="form-group d-flex justify-content-center">

<input type="submit" name="submit" value="Upload" class="btn btn-success rounded-0 px-3">











It will help you...

#PHP 8