Upload Multiple Images Preview using PHP

Today, We want to share with you Upload Multiple Images Preview using jQuery, Ajax and PHP.In this post we will show you upload image using ajax without form, hear for How to upload a file in Ajax without using a form in PHP we will give you demo and example for implement.In this post, we will learn about Upload Multiple Images With Image Preview Using jQuery,Ajax And PHP with an example.

Upload Multiple Images Preview using jQuery, Ajax and PHP

There are the Following The simple About Upload Multiple Images Preview using jQuery, Ajax and PHP Full Information With Example and source code.

As I will cover this Post with live Working example to develop AJAX Image and File Upload in PHP with jQuery, so the multiple image upload in php with database for this example is following below.

Ajax Image Upload using PHP and jQuery

<!DOCTYPE html>
<html>
<head>
  <title>Ajax Upload Multiple Images without submit</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
$(document).on("click", "#upload", function() {
    var getall_data = [];
    var fileSelect = document.getElementById('files');
    var files = fileSelect.files;
    var formData = new FormData();

    for (var i = 0; i < files.length; i++) {
        var file = files[i];

        if (!file.type.match('image.*')) {
            continue;
        }
        formData.append('product_images[]', file, file.name);
    }

    $.ajax({  
        url: "do_data_upload.php",  
        type: "POST",  
        data: formData,  
        contentType: false,  
        processData:false,  
        success: function(files,data,xhr)  
        {           
          console.log(files);
           getall_data.push(files);
           $('#preview_all_images').html("<pre>" + getall_data + "</pre>");
        }  
    }); 
});

function preview_images() 
{
 var total_file=document.getElementById("files").files.length;
 for(var i=0;i<total_file;i++)
 {
  $('#image_preview').append("<div><img class='img-responsive' src='"+URL.createObjectURL(event.target.files[i])+"' width='25px' height='25px'></div>");
 }
}
</script>
</head>
<body>
  <h3>Upload Multiple Images using jQuery, Ajax and PHP</h3>
  <p>How to upload multiple image upload without submit button using ajax jquery?</p>
<div id="preview_all_images"></div>
 <div class="row" id="image_preview"></div>
<input name="files[]" type="file" multiple id="files" onchange="preview_images();"/>  
<button id="upload">Get External Content</button>
<a href="https://www.pakainfo.com/" target="_blank" alt="pakainfo" title="pakainfo">Free Download Example - Pakainfo.com</a>

</body>
</html>

do_data_upload.php
<?php
$countfiles = count($_FILES['product_images']['name']);

 // Looping all files
 for($i=0;$i<$countfiles;$i++){
   $filename = $_FILES['product_images']['name'][$i];
   
   // Upload file
   move_uploaded_file($_FILES['product_images']['tmp_name'][$i],'uploads/'.$filename);
    
 }
print_r($_FILES);

//var_dump($_FILES);
?>

Angular 6 CRUD Operations Application Tutorials

Read :

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about Upload Multiple Images Preview using jQuery, Ajax and PHP.
I would like to have feedback on my Pakainfo.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.


Related FAQ

Here are some more FAQ related to this Article:

  1.   frontaccounting Customization create module form Components
  2.   jQuery Ajax File Upload images using PHP MySQLi
  3.   jquery multiple Image Upload with preview and Delete using PHP
  4.   VueJs Dynamic Class and Style Bindings
  5.   Jquery Ajax Form Submit examples using PHP
  6.   Upload Multiple Images With Image Preview Using jQuery,Ajax And PHP
  7.   Dynamically Upload Multiple Images Using PHP and jQuery
  8.   Ajax not working in laravel 5.6
  9.   How to add custom jquery image validation?
  10.   jQuery Print Dynamic Content using PHP MySQL Example