PHP Multiple File Upload Example


Share:
Published By: Admin, Published On: Apr 15, 2021, Category: PHP

Hi Guys,

In this blog, I’ll explain the basics of multiple file upload in PHP.

In PHP, it is possible to upload multiple files utilizing a single input file element. You just need to customize your single file upload PHP code and enable your file element to cull multiple files.

Before we started are some steps to enable multiple files uploads in <form>.

First, create a <form> and add enctype='multiple/form-data' attribute.

Create an input type='file' element and for enabling multiple files selection add multiple attribute. For reading all selected files when <form> submitted add [] brackets at the end of a name which denotes an Array.

In this example i use following files for html and php that way we can make simple example:

Ok, now you can see below example source code and also check demo goes on upload an file and then click submit button file uploaded own directory.

Example First we created... Step:1 multiple_file.php
<!DOCTYPE html>
<html lang="en">
<head>
    PHP Multiple File Upload Example - MyWebtuts.com
    
    
    
    
</head>
<body>

PHP Multiple File Upload

</body> </html>

And now another backend file created store image in your directory Step:2 multiple_file_upload.php


    <?php

        if(isset($_POST['submit'])){
     
         // Count total files
         $count_files = count($_FILES['file']['name']);
         // Looping all files
         for($i=0;$i<$count_files;$i++){
          $filename = $_FILES['file']['name'][$i];
         
          // Upload file
          move_uploaded_file($_FILES['file']['tmp_name'][$i],'multiple_file_upload/'.$filename);
          
         }
           header("location:multiple_file.php");
        }

    ?>

It will help you..

Share: