When i remove the Images from the Preview(its not Uploaded into the DB), it still is in there as a File and gets Uploaded. My Code literally removes the Image from the Frontend but it still gets Uploaded and i could not find a Way to delete the File i wanted to delete, and some even said it is not possible since FileReader is read only! Now is there a Way to workaround that or do i have to delete my Code and Start new?
I have read on several Websites that it is not possible to do it and then they showed completely new Code. But i want to find a Way that it is possible to bypass this.
Here is my Code:
JS:
$(function() {
// Multiple images preview in browser
var imagesPreview = function(input, placeToInsertImagePreview) {
if (input.files) {
var filesAmount = input.files.length;
for (i = 0; i < filesAmount; i++) {
var reader = new FileReader();
reader.onload = function(event) {
$('<div class="previewdeleter position-relative" data-item-id-div="input.files[i].length" style="height:200px;width: 200px; display: inline-block; position: relative !important;">' +
'<img alt="" src='+event.target.result+' style="height:200px;width: 100%; display: inline-block;">' +
'<div class="position-absolute" style="top: 0;right: 0;">' +
'<img src="/x.png" class="image-deletepreview" style="height: 20px; display: inline-block;"></div></div>')
.appendTo(placeToInsertImagePreview);
$('.image-deletepreview').on('click', function(e) {
e.preventDefault();
var deletepreview = $(this).parent().parent().remove();
console.log(deletepreview);
});
}
reader.readAsDataURL(input.files[i],);
}
}
};
MY HTML:
<input value="" type="file" id="images" name="images[]" accept="image/*" multiple />
<div id="previewHolder" data-item-id-div="input.files[i].length" multiple="" class="previewdeleter position-relative">
<div class="position-absolute delete-image">
</div>
</div>
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire