Upload Multiple Images With Image Preview Using jQuery,Ajax And PHP

Upload Multiple Images With Image Preview Using jQuery,Ajax And PHP

In this Post We Will Explain About is Upload Multiple Images With Image Preview Using jQuery,Ajax And PHP With Example and Demo.Welcome on Pakainfo.com – Examples, The best For Learn web development Tutorials,Demo with Example! Hi Dear Friends here u can know to How to Upload multiple images jQuery Ajax using PHP Example

In this post we will show you Best way to implement multiple image upload with preview and delete jquery, hear for Upload Multiple Images using jQuery, PHP & MySQL with Download .we will give you demo,Source Code and examples for implement Step By Step Good Luck!.

How to Upload multiple images jQuery Ajax using PHP

In this Example,First of all Add or Inluce External Libs Like as a(jQuery, css etc..), and then create a simple index.php or index.html page.After that crate a simple javascript file like as a index.js or main.js, It is also add your web-application First Header Part to some priorty set.After that Include your relavant CSS Class.

  Angular 9/8 Select Dropdown | Get Selected DropDown Value on Change Event

How to Upload multiple images jQuery Ajax using PHP

index.php

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<link href="css/uploadfilemulti.css" rel="stylesheet">
<!-- Devloped by Pakainfo.com free download examples -->
<script src="js/jquery-1.8.0.min.js"></script>
<script src="js/jquery.fileuploadmulti.min.js"></script>
</head>
<body>
<!-- Devloped by Pakainfo.com free download examples -->
<div id="liveMultipleFileupload">Upload</div>

<div id="data_status"></div>
<script>

$(document).ready(function()
{

var settings = {
	//send url to all images
	url: "upload.php",
	method: "POST",
	allowedTypes:"jpg,png,gif,doc,pdf,zip",
	fileName: "liveuploadFile",
	multiple: true,
	onSuccess:function(files,data,xhr)
	{
		$("#data_status").html("<font color='green'>Upload is success</font>");
        },
        afterUploadAll:function()
        {
                alert("Good Luck all images uploaded!!");
        },
	onError: function(files,data_status,errMsg)
	{		
		$("#data_status").html("<font color='red'>Your Upload is Failed</font>");
	}
}
$("#liveMultipleFileupload").uploadFile(settings);

});
</script>
</body>

upload.php

simple File contains post upload all the files process as well as move all files in uploads Folder.

<?php
$output_dir = "uploads/";

if(isset($_FILES["liveuploadFile"]))
{
	$results = array();

	$error =$_FILES["liveuploadFile"]["error"];
   {

    	if(!is_array($_FILES["liveuploadFile"]['name'])) //get here single file
    	{
            $get_randomNo   = time();

            $LiveImgName      = str_replace(' ','-',strtolower($_FILES['liveuploadFile']['name']));
            $ImageType      = $_FILES['liveuploadFile']['type']; 

            $LiveImgExt = substr($LiveImgName, strrpos($LiveImgName, '.'));
            $LiveImgExt       = str_replace('.','',$LiveImgExt);
            $LiveImgName      = preg_replace("/\.[^.\s]{3,4}$/", "", $LiveImgName);
            $NewLiveImgName = $LiveImgName.'-'.$get_randomNo.'.'.$LiveImgExt;

       	 	move_uploaded_file($_FILES["liveuploadFile"]["tmp_name"],$output_dir. $NewLiveImgName);
       	 	 //echo "<br> Error: ".$_FILES["liveuploadFile"]["error"];

	       	 	 $results[$fileName]= $output_dir.$NewLiveImgName;
    	}
    	else
    	{
            $fileCount = count($_FILES["liveuploadFile"]['name']);
    		for($i=0; $i < $fileCount; $i++)
    		{
                $get_randomNo   = time();

                $LiveImgName      = str_replace(' ','-',strtolower($_FILES['liveuploadFile']['name'][$i]));
                $ImageType      = $_FILES['liveuploadFile']['type'][$i]; //"image/png", image/jpeg etc.

                $LiveImgExt = substr($LiveImgName, strrpos($LiveImgName, '.'));
                $LiveImgExt       = str_replace('.','',$LiveImgExt);
                $LiveImgName      = preg_replace("/\.[^.\s]{3,4}$/", "", $LiveImgName);
                $NewLiveImgName = $LiveImgName.'-'.$get_randomNo.'.'.$LiveImgExt;

                $results[$NewLiveImgName]= $output_dir.$NewLiveImgName;
    		    move_uploaded_file($_FILES["liveuploadFile"]["tmp_name"][$i],$output_dir.$NewLiveImgName );
    		}
    	}
    }
    echo json_encode($results);

}

?>

List of all Google Adsense, VueJS, AngularJS, PHP, Laravel Examples.


Download Project Scripts

First of all check Folder and get some error and then check if create single file coming then simple process separate if all the multiple files handle in php loop.

  jQuery Ajax Upload Multiple Images using PHP

$get_randomNo   = time();

$LiveImgName      = str_replace(' ','-',strtolower($_FILES['liveuploadFile']['name'][$i]));
$ImageType      = $_FILES['liveuploadFile']['type'][$i]; //"image/png", image/jpeg etc.

$LiveImgExt       = substr($LiveImgName, strrpos($LiveImgName, '.'));
$LiveImgExt       = str_replace('.','',$LiveImgExt);
$LiveImgName      = preg_replace("/\.[^.\s]{3,4}$/", "", $LiveImgName);
$NewLiveImgName   = $LiveImgName.'-'.$get_randomNo.'.'.$LiveImgExt;

Add simple using PHP UNIX time stamp with create image name to generated unique name.

You are Most welcome in my youtube Channel Please subscribe my channel. and give me FeedBack.
More Details……
Angularjs Example

Example

I hope you have Got What is How to Upload multiple images jQuery Ajax using PHP And how it works.I would Like to have FeedBack From My Blog(Pakainfo.com) readers.Your Valuable FeedBack,Any Question,or any Comments about This Article(Pakainfo.com) Are Most Always Welcome.


Related FAQ

Here are some more FAQ related to this Article:

  1.   AngularJS Get Current Date Time Example
  2.   PHP Curl POST and GET Methods
  3.   HTML PHP Ajax Progress Bar
  4.   PHP Jquery Ajax Upload Multiple Images with Preview
  5.   jQuery Ajax Multiple File Upload Using PHP
  6.   jQuery AJAX Multiple Files Upload using PHP
  7.   Access Tokens - Facebook Login - Facebook Open Graph API
  8.   PHP and Ajax Asynchronous File Upload using jQuery
  9.   Dynamically Upload Multiple Images Using PHP and jQuery
  10.   Upload Multiple Images Preview using PHP

Leave a Reply

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