I have a module that uploading image files to the server. Now I am trying to add preview and delete function to that before uploading to the server. When I press Remove, it removes from previews, but the image files still stay in the list and will be uploaded to the server when I press the Upload button. How to remove that files from the list too?
This is html part
<form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post"
enctype="multipart/form-data">
<input type="file" id="file" name="file[]" multiple />
<p><div id="image-holder"></div></p>
<input type="submit" name="upload" value="Click to upload file">
</form>
here is jquery part
var abc = 0;
$(document).ready(function() {
if (window.File && window.FileList && window.FileReader) {
$("#file").on("change", function(e) {
var files = e.target.files,
filesLength = files.length;
var image_holder = $("#image-holder");
abc += 1;
var z = abc - 1;
for (var i = 0; i < filesLength; i++) {
var f = files[i]
var fileReader = new FileReader();
fileReader.onload = (function(e) {
var file = e.target;
$("<span class=\"pip\" id='abcd" + abc + "'>" +
"<img class=\"imageThumb\" src=\"" + e.target.result + "\" alt=\"" + file.name + "\" +title=\"" + file.name + "\"/>" +
"<br/><span class=\"remove\">Remove</span>" +
"</span>").appendTo(image_holder);
$(".remove").click(function(){
$(this).parent(".pip").remove();
});
});
fileReader.readAsDataURL(f);
}
});
}
});
I think It's sort of same problem if I add another file, it will only upload the last file only not including previously selected files.