Home » PHP Jquery Ajax Upload Multiple Images with Preview

PHP Jquery Ajax Upload Multiple Images with Preview

Today, We want to share with you PHP Jquery Ajax Upload Multiple Images with Preview Example.In this post we will show you multiple image upload in laravel using ajax, hear for multiple image upload in php with database we will give you demo and example for implement.In this post, we will learn about multiple image upload with preview and delete jquery php with an example.

PHP Jquery Ajax Upload Multiple Images with Preview Example

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

Read Also:  Remove null from array Jquery Example

As I will cover this Post with live Working example to develop how to upload multiple images in php using for loop, so the some image upload using ajax php mysql for this example is following below.

Step 1 : Javascript Code:

jQuery Source code

            $('#status').html('<img src="image.gif"/>');
            $('#status').html('Sorry Your products_img uploading failed, please try again.');

Step 2 : HTML Code:

HTML Source Code:

<form method="post" id="submitForm" enctype="multipart/form-data" action="upload.php">
    <label>Choose products_img</label>
    <input type="file" name="products_img[]" id="imgs" multiple >
    <input type="submit" name="submit" value="UPLOAD"/>
<div id="status"></div>

<div class="gallery" id="products_imgPrev"></div>

Step 3 : PHP Source Code:

PHP Code: (upload.php)


    $target_dir = "uploads/";
    $allow_types = array('jpg','png','jpeg','gif');
    $products_img_arr = array();
    foreach($_FILES['products_img']['name'] as $key=>$val){
        $image_name = $_FILES['products_img']['name'][$key];
        $tmp_name   = $_FILES['products_img']['tmp_name'][$key];
        $size       = $_FILES['products_img']['size'][$key];
        $type       = $_FILES['products_img']['type'][$key];
        $error      = $_FILES['products_img']['error'][$key];
        $file_name = basename($_FILES['products_img']['name'][$key]);
        $uploadFileImgDir = $target_dir . $file_name;
        $file_type = pathinfo($uploadFileImgDir,PATHINFO_EXTENSION);
        if(in_array($file_type, $allow_types)){    
                $products_img_arr[] = $uploadFileImgDir;
    if(!empty($products_img_arr)){ ?>
        <?php foreach($products_img_arr as $image_src){ ?>
            <li><img src="<?php echo $image_src; ?>" alt=""></li>
        <?php } ?>
<?php }

Angular 6 CRUD Operations Application Tutorials

Read :

Read Also:  open new tab in reactjs Example Tutorial


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

I hope you get an idea about PHP Jquery Ajax Upload Multiple Images with Preview Example.
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. Read Also:  how to create registration form in wordpress without plugin?
  2. Read Also:  Event binding on dynamically created elements?
  3. Read Also:  Upload Multiple Images Preview using PHP
  4. Read Also:  PHP and Ajax Asynchronous File Upload using jQuery
  5. Read Also:  How to Add header and footer in PDF page using DOMPDF?
  6. Read Also:  Increment Decrement with Laravel 6 Example
  7. Read Also:  PHP MySQL Dynamic SQL Insert Query
  8. Read Also:  Convert JavaScript Array to JSON Example
  9. Read Also:  javascript Text Avatar Plugin Like Gmail
  10. Read Also:  How to get current url with or without query string using Vuejs

Leave a Comment

Your email address will not be published. Required fields are marked *