I'm using this awesome tutorial to preview multiple image before upload.
Now I need to put some information, file name & file size.
Below is the sample:
And the JS:
function previewImages()
{
var preview = document.querySelector('.gallery');
if(this.files)
{
[].forEach.call(this.files, readAndPreview);
}
function readAndPreview(file)
{
if (!/\.(jpe?g|png|gif)$/i.test(file.name))
{
return alert(file.name + " is not an image");
}
var reader = new FileReader();
reader.addEventListener("load", function() {
var image = new Image();
image.width = 150;
image.height = 150;
image.title = file.name;
image.src = this.result;
preview.appendChild(image);
});
reader.readAsDataURL(file);
}
}
document.querySelector('#uploadFile').addEventListener("change", previewImages);
HTML:
<span class="btn btn-default btn-file">
Browse <input type="file" name="uploadFile" id="uploadFile" multiple="multiple"/>
</span>
<div class="gallery" style="display: flex; flex-wrap: wrap;"></div>
I know to get the file size and file name is using this: file.size
& file.name
.
But now how to put that information on my code?
And 1 more how to add delete button for each image and function to delete it?