PHP Multiple Image Upload With Preview Example

Apr 16, 2021 . Admin

Hi Guys,

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

In PHP, it is possible to upload multiple images utilizing a single input file element. You just need to customize your single images 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 image and then click submit button image uploaded own directory.

Example

First we created.. Step:1 multiple_img.php


<html lang="en">
<head>
    PHP Multiple Image Upload Example - MyWebtuts.com
    
    
    
    
    

    
        
</head>
<body>

PHP Multiple Images Upload

</body> </html>

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

<?php

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

It will help you..

#PHP