"Multiple upload image, Preview image and draggable element by sortable"
Bootstrap 4.0.0 Snippet by bnk2972

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<link href="//maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css">
<script src="//maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
<script src="//code.jquery.com/jquery-1.11.1.min.js"></script>
<!------ Include the above in your HEAD tag ---------->
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<div class="container">
<fieldset class="form-group">
<a href="javascript:void(0)" onclick="$('#pro-image').click()">Upload Image</a>
<input type="file" id="pro-image" name="pro-image" style="display: none;" class="form-control" multiple>
</fieldset>
<div class="preview-images-zone">
<div class="preview-image preview-show-1">
<div class="image-cancel" data-no="1">x</div>
<div class="image-zone"><img id="pro-img-1" src="https://img.purch.com/w/660/aHR0cDovL3d3dy5saXZlc2NpZW5jZS5jb20vaW1hZ2VzL2kvMDAwLzA5Ny85NTkvb3JpZ2luYWwvc2h1dHRlcnN0b2NrXzYzOTcxNjY1LmpwZw=="></div>
<div class="tools-edit-image"><a href="javascript:void(0)" data-no="1" class="btn btn-light btn-edit-image">edit</a></div>
</div>
<div class="preview-image preview-show-2">
<div class="image-cancel" data-no="2">x</div>
<div class="image-zone"><img id="pro-img-2" src="https://www.codeproject.com/KB/GDI-plus/ImageProcessing2/flip.jpg"></div>
<div class="tools-edit-image"><a href="javascript:void(0)" data-no="2" class="btn btn-light btn-edit-image">edit</a></div>
</div>
<div class="preview-image preview-show-3">
<div class="image-cancel" data-no="3">x</div>
<div class="image-zone"><img id="pro-img-3" src="http://i.stack.imgur.com/WCveg.jpg"></div>
<div class="tools-edit-image"><a href="javascript:void(0)" data-no="3" class="btn btn-light btn-edit-image">edit</a></div>
</div>
</div>
</div>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
.preview-images-zone {
width: 100%;
border: 1px solid #ddd;
min-height: 180px;
/* display: flex; */
padding: 5px 5px 0px 5px;
position: relative;
overflow:auto;
}
.preview-images-zone > .preview-image:first-child {
height: 185px;
width: 185px;
position: relative;
margin-right: 5px;
}
.preview-images-zone > .preview-image {
height: 90px;
width: 90px;
position: relative;
margin-right: 5px;
float: left;
margin-bottom: 5px;
}
.preview-images-zone > .preview-image > .image-zone {
width: 100%;
height: 100%;
}
.preview-images-zone > .preview-image > .image-zone > img {
width: 100%;
height: 100%;
}
.preview-images-zone > .preview-image > .tools-edit-image {
position: absolute;
z-index: 100;
color: #fff;
bottom: 0;
width: 100%;
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
$(document).ready(function() {
document.getElementById('pro-image').addEventListener('change', readImage, false);
$( ".preview-images-zone" ).sortable();
$(document).on('click', '.image-cancel', function() {
let no = $(this).data('no');
$(".preview-image.preview-show-"+no).remove();
});
});
var num = 4;
function readImage() {
if (window.File && window.FileList && window.FileReader) {
var files = event.target.files; //FileList object
var output = $(".preview-images-zone");
for (let i = 0; i < files.length; i++) {
var file = files[i];
if (!file.type.match('image')) continue;
var picReader = new FileReader();
picReader.addEventListener('load', function (event) {
var picFile = event.target;
var html = '<div class="preview-image preview-show-' + num + '">' +
'<div class="image-cancel" data-no="' + num + '">x</div>' +
'<div class="image-zone"><img id="pro-img-' + num + '" src="' + picFile.result + '"></div>' +
'<div class="tools-edit-image"><a href="javascript:void(0)" data-no="' + num + '" class="btn btn-light btn-edit-image">edit</a></div>' +
'</div>';
output.append(html);
num = num + 1;
});
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Related: See More


Questions / Comments:

How to submit images to server

abdalrahmanabunada (1) - 6 years ago - Reply 1


remove $("#pro-image").val('');

xrodolfochangx (0) - 6 years ago - Reply 0


and add in attr of input name="pro-image[]"

xrodolfochangx (0) - 6 years ago - Reply 0


Thank you!!~~!

mokaim () - 4 years ago - Reply 0


Sir i am facing a issue,when i cancel the image to upload it just remove the image from displaying but it upload on the server.

kindly tell me that how i can delete that image from the input field?

sameerkhan1 () - 4 years ago - Reply 0


i can upload image with code: document.getElementById('pro-image').addEventListener('change', readImage, false);

padi-dev-dungnv () - 4 years ago - Reply 0


How do I allow for the images to be saved onto a server?

nkushh () - 5 years ago - Reply 0


How to get order Image to server

tonamz () - 5 years ago - Reply 0


Add the name attribute value between the ' ' symbols on .val(' '). For example if your form field has the attribute name='images[]', add the images[] to .val('images[]')

nkushh () - 5 years ago - Reply 0


filename show empty after add value

please help

hotflashers () - 3 years ago - Reply 0


filename show empty after add value.

please help.

hotflashers () - 3 years ago - Reply 0


filename show empty after add value.

please help.

hotflashers () - 3 years ago - Reply 0


It's not working with jquery3 .Is it possible same tasks will perform with jquery3. Drag Drop not working with Jquery3

Sobia () - 5 years ago - Reply 0