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.

Also Read This πŸ‘‰   php curl rest api example - How to call REST API using CURL in php?

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 :

Also Read This πŸ‘‰   jQuery Ajax File Upload images using PHP MySQLi


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 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.