How to upload multiples file or folder in database

Project : in this project we will learn how to upload multiples files or zip in folder and in database.

Before uploading multiple files or larger file bigger than 2MB, Please configure php.ini in xampp or wamp. Find these two line
post_max_size=8M increase limit in php.ini
upload_max_filesize=5M increase limit
index.php
                
                  <?php include("upload.php");  ?>
                    <!DOCTYPE html>
                    <html>
                    <head>
                      <link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">
                    </head>
                    <body>
                      <div class="container "><br>
                          <div class="row mt-2">
                              <div class="col-md-6 offset-3 border p-2" style="background: #f5f6fa;"> 
                                <div class="w-100 text-center"><?php echo $error; ?><?php echo $msg; ?></div>    
                                <form method="POST" action="index.php" enctype="multipart/form-data"><br>
                                  <h3 class="rounded bg-primary w-100 p-2 text-white text-center">Upload Multiple Files </h3>  
                                  <div class="form-group">
                                    <label for="file"><b>Upload Files :</b></label>
                                    <input type="file" name="myfile[]" id="myfile" class="form-control" multiple="" directory="" style="height: 44PX;" >
                                </div><br>
                                <div class="form-group">
                                  <input type="submit" name="file" class="btn btn-success" value="Upload">
                                </div>
                              </form>
                            </div>
                            </div><br>       
                      </div>
                    </body>
                    </html>
                
            

Upload Form

index.php
PHP

Create table in database

Table in database
                
                CREATE TABLE `images` (
                  `id` int(11) NOT NULL,
                  `pic_name` varchar(255) NOT NULL,
                  `creatde_at` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
                ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
                
            
Create connection with database
myproject/dbcon.php
dbcon.php
    
        $dbhost ="localhost";
        $dbuser ="root";
        $dbpswd ="";
        $dbname ="dbdemo";
        $dbcon= mysqli_connect($dbhost,$dbuser,$dbpswd,$dbname);
        if($dbcon){
            //echo "Connected............!!!";
            return $dbcon;
            exit();
        }else{
            die("Connection failed ? ? ?". mysqli_error($dbcon));
        }
        mysqli_close($dbcon);
    

Process to Upload Multiple Files

Process to upload multiple files.

upload.php
                
                  <?php 
                    include('dbcon.php');
                    $c = 0;
                    $error=''; $msg='';
                    if(isset($_POST['file'])){
                      foreach($_FILES['myfile']['name'] as $x => $filename){
                        if(strlen($_FILES['myfile']['name'][$x]) > 1){
                            if(move_uploaded_file($_FILES['myfile']['tmp_name'][$x], 'uploads/'.$filename)){
                              $c++;
                              $sql = "INSERT INTO images(`pic_name`) VALUES('$filename')";
                              $run = mysqli_query($dbcon,$sql);
                              $msg = "
The files or folder has been uploaded
"; $filename=''; }else{ $error = "
Something went wrong
"; } }else{ $error = "
Something went wrong
"; } } }

css folder

You must download and include bootstrap css source files for good interface OR You can add cdn link from bootstrap website.
myproject/css
bootstrap.min.css