PHP Ajax Multiple Image Upload with Preview Example

By Hardik Savani November 5, 2023 Category : PHP jQuery Ajax

Today, i would like to share with you multiple image upload with preview using jquery ajax in PHP. This Tutorial will help to learn JQuery Ajax multiple images upload example in PHP with demo. demo of display selected multiple images preview.

Sometime, we may need to add feature for multiple images upload. If you are new in core PHP or don't know how to do it then you are a right place. Here i will give you full example of multiple images upload with display preview of selected images. So don't worry and just follow bellow two files.

In this example, i simple create two files as there are listed bellow:

1) index.php

2) uploadFile.php

In index file i write code for design and jquery ajax code. After click on submit button all selected images will be upload on "media" folder. So you must require to create "media" folder in your root directory. Here i give you very small and quick example.

You can see bellow code of display selected images preview:



var total_file=document.getElementById("uploadFile").files.length;

for(var i=0;i





Ok, now we will see full example of index.php and uploadFile.php, after successfully this example you can see like as bellow preview:



<!DOCTYPE html>



<title>PHP Ajax Multiple Image Upload with Preview Example</title>

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

<script src="//"></script>

<script src=""></script>

<style type="text/css">


display: inline;



border: 1px solid black;

padding: 10px;


#image_preview img{

width: 200px;

padding: 5px;





<div class="container">

<h1>PHP Ajax Multiple Image Upload with Preview Example</h1>

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

<input type="file" id="uploadFile" name="uploadFile[]" multiple/>

<input type="submit" class="btn btn-success" name='submitImage' value="Upload Image"/>



<div id="image_preview"></div>



<script type="text/javascript">



var total_file=document.getElementById("uploadFile").files.length;

for(var i=0;i<total_file;i++)


$('#image_preview').append("<img src='"+URL.createObjectURL([i])+"'>");





alert("Uploaded SuccessFully");












move_uploaded_file($_FILES["uploadFile"]["tmp_name"][$i], "$folder".$_FILES["uploadFile"]["name"][$i]);





Make sure to create "media" folder in your root directory.

I hope it can help you...