PHP 8 Upload Multiple Files and Store in MySQL Database

Jun 03, 2022 . Admin

Hello Friends,

Here, I will show you how to works PHP 8 Upload Multiple Files and Store in MySQL Database. We will look at example of How to upload multiple files and store in the MySQL database using PHP 8. I explained simply step by step Upload Multiple Files to Store in MySQL Database Using PHP 8. I explained simply about How to Upload multiple files into Database in PHP 8/MySQLi. Follow bellow tutorial step of PHP 8 Multiple Files Upload in MySQL Database.

This article will give you simple example of Multiple File Upload with PHP 8 And MySQL.

So, let's see bellow solution:

<!DOCTYPE html>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>PHP 8 Upload Multiple Files and Store in MySQL Database</title>
    <link href="" rel="stylesheet">
    if (isset($_FILES['file'])) {

        $dontallowedFileType = array('image/jpg','image/png','image/jpeg');
        $servername = "localhost";
        $username = "root";
        $password = "";
        $dbname = "db_php";

        $conn = mysqli_connect($servername, $username, $password, $dbname);

        if (!$conn) {
            die("connection failed:" .mysqli_connect_error());
            echo "connection successfull";

        $count = count($_FILES['file']['name']);

        for ($i=0; $i <$count ; $i++) { 
            $file_name = $_FILES['file']['name'][$i];
            $file_size = $_FILES['file']['size'][$i];    
            $file_tmp = $_FILES['file']['tmp_name'][$i];     
            $file_type = $_FILES['file']['type'][$i];

            if(!in_array($file_type, $dontallowedFileType)){
                if(move_uploaded_file($file_tmp ,"pathname/".$file_name)){
                    $sql="INSERT INTO files(file,type,size) VALUES('$file_name','$file_type','$file_size')";
                    if ($conn->query($sql)===TRUE) {
                        $msg = "<p class='alert alert-primary mb-0 p-2'>File inserted Successfully!</p>";
                        $msg = "<p class='alert alert-danger mb-0 p-2'>Error :".$sql."<br>".$conn->error."</p>";
                    $msg = "<p class='alert alert-danger mb-0 p-2'>File Was Not inserted!</p>";
                $msg = "<p class='alert alert-danger mb-0 p-2'>please select valid file !</p>";

    <div class="container mt-5">

        <div class="card">
            <div class="card-header text-center bg-primary text-white">
                <h3>PHP 8 Upload Multiple Files and Store in MySQL Database -</h3>
            <div class="card-body" style="height: 200px;">
                <?php echo $msg; ?>
                <form action="" method="post" enctype="multipart/form-data" > 
                    <input type="file" name="file[]" multiple class="form-control mt-3">
                    <div class="d-flex justify-content-center">
                        <input type="submit" name="upload" class="btn btn-primary mt-5"></input>




It will help you...

#PHP 8