jQuery AJAX Add Delete Multiple Image Upload

jQuery AJAX Add Delete Multiple Image Upload

Today, We want to share with you jQuery AJAX Add Delete Multiple Image Upload.In this post we will show you jquery multiple image upload with preview and delete demo, hear for Ajax Multiple Image Upload with Edit Delete using PHP Mysql 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.

jQuery AJAX Add Delete Multiple Image Upload

There are the Following The simple About jQuery AJAX Add Delete Multiple Image Upload Full Information With Example and source code.

As I will cover this Post with live Working example to develop how to fetch image from database in php using ajax, so the Delete the uploded image file using ajax code for this example is following below.

Upload and delete image file with jQuery and AJAX

index.php

<html>
<head>
<title>Add Delete Image via jQuery AJAX - www.pakainfo.com</title>
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script type="text/javascript">
$(document).ready(function (e) {
	$("#productSubmit").on('submit',(function(e) {
		e.preventDefault();
		$.ajax({
        	url: "upload.php",
			type: "POST",
			data:  new FormData(this),
			contentType: false,
    	    cache: false,
			processData:false,
			success: function(data)
		    {
			$("#previewData").html(data);
		    },
		  	error: function(){} 	        
	   });
	}));	
});
function removeFiles(path) {
	$.ajax({
		url: "delete.php",
		type: "POST",
		data:  {'path':path},
		success: function(data){
			$("#previewData").html('<div class="no-image">No Image</div>');
		},
		error: function(){} 	        
	});
}
</script>
<style>
body {
font-family: Arial;
font-size: 14px;
}
.bgColor {
width: 440px;
height:100px;
background-color: #c8f5ff;
color: #000;
padding: 2px;
}
.bgColor label{
font-weight: bold;
color: #A0A0A0;
}
#previewData{
float:left;
width:100px;
height:100px;
text-align:center;
font-weight: bold;
color: #C0C0C0;
background-color: #F0E8E0;
position:relative;
}
#productSubmitLayer{
float:right;
padding: 10px;
}
.btnSubmit {
background-color: #3FA849;
padding:4px;
border: #3FA849 1px solid;
color: #FFFFFF;
}
.inputFile {
padding: 3px;
background-color: #FFFFFF;
}

.image-container {
	display:inline-block;
	position:relative;
}
.image-delete {
	position: absolute;
    right: 30px;
    top: 30px;
    border: #FFF 4px solid;
    border-radius: 50%;
    padding: 7px 10px;
    display: none;
    cursor: pointer;
    opacity: 0.6;
    color: #FFF
}
.no-image {
	display: inline-block;
    position: absolute;
    right: 18px;
    top: 40px;
}
</style>
</head>
<body>
<div class="bgColor">
<form id="productSubmit" action="upload.php" method="post">
<div id="previewData"><div class="no-image">No Image</div></div>
<div id="uploadFormLayer">
<label>Upload Image File:</label><br/>
<input name="uploadedFiles" type="file" class="inputFile" />
<input type="submit" value="Submit" class="btnSubmit" />
</form>
</div>
</div>
</body>
</html>

upload.php

<style>
.image-container:hover .image-delete{display:inline-block;}
</style>
<?php
if(is_array($_FILES)) {
if(is_uploaded_file($_FILES['uploadedFiles']['tmp_name'])) {
$sourcePath = $_FILES['uploadedFiles']['tmp_name'];
$orignalsetPath = "images/".$_FILES['uploadedFiles']['name'];
if(move_uploaded_file($sourcePath,$orignalsetPath)) {
?>
<div class="image-container"><img src="<?php echo $orignalsetPath; ?>" width="100px" height="100px"  /><div class="image-delete" onClick="removeFiles('<?php echo $orignalsetPath; ?>')">X</div></div>
<?php
}
}
}
?>

delete.php

<?php
if(!empty($_POST["path"])) {
	unlink($_POST["path"]);
}
?>

Web Programming Tutorials Example with Demo

Read :

  PHP Dynamically Add Remove Images Upload using Ajax

Summary

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

I hope you get an idea about jQuery AJAX Add Delete Multiple Image Upload.
I would like to have feedback on my infinityknow.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.

Leave a Reply

avatar
  Subscribe  
Notify of