Sindbad~EG File Manager
var abc = 0; // Declaring and defining global increment variable.
$(document).ready(function() {
//var image_id = $("#image_id").val();
var modal = document.getElementById('myModal');
// Get the image and insert it inside the modal - use its "alt" text as a caption
// //var img = document.getElementById('myImg'+image_id);
var modalImg = document.getElementById('img01');
var captionText = document.getElementById('caption');
$('.myImg').click(function() {
modal.style.display = "block";
modalImg.src = this.src;
captionText.innerHTML = this.alt;
});
// Get the <span> element that closes the modal
var span = document.getElementsByClassName("close")[0];
// When the user clicks on <span> (x), close the modal
span.onclick = function() {
modal.style.display = "none";
}
// To add new input file field dynamically, on click of "Add More Files" button below function will be executed.
$('#add_more').click(function() {
$(this).before($("<div/>", {
id: 'filediv',
class: 'row'
}).fadeIn('slow').append($("<input/>", {
name: 'files[]',
type: 'file',
id: 'file'
}), $("<br/><br/>")));
});
// Following function will executes on change event of file input to select different file.
$('body').on('change', '#file', function() {
if (this.files && this.files[0]) {
abc += 1; // Incrementing global variable by 1.
var z = abc - 1;
var x = $(this).parent().find('#previewimg' + z).remove();
$(this).before("<div class='col-md-6 margin20 text-left' id='divImage" + abc + "'><img id='previewimg" + abc + "' height='110px' src=''/></div><div class='col-md-2' id='divRemove" + abc + "' ></div>");
var reader = new FileReader();
reader.onload = imageIsLoaded;
reader.readAsDataURL(this.files[0]);
$(this).hide();
$("#divRemove" + abc).append($("<input/>", {
type:'button',
id: 'btnremove',
value: 'Cancel',
class: 'btn btn-danger'
}).click(function() {
$(this).parent().parent().remove();
}));
}
});
// To Preview Image
function imageIsLoaded(e) {
$('#previewimg' + abc).attr('src', e.target.result);
};
});
Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists