Hello everyone, I need assistance with the code below.
function fileValidation() {
var fileInput = document.getElementById('filech');
var filePath = fileInput.value;
var allowedExtensions = /(\.jpg|\.jpeg|\.png|\.gif)$/i;
if (!allowedExtensions.exec(filePath)) {
alert('error .jpeg/.jpg/.png/.gif ');
fileInput.value = '';
return false;
} else {
//Image preview
if (fileInput.files && fileInput.files[0]) {
var reader = new FileReader();
reader.onload = function(e) {
document.getElementById('imagePreview').innerHTML = '<img src="' + e.target.result + '"/>';
};
reader.readAsDataURL(fileInput.files[0]);
}
}
}
To upload multiple photos:
<input id="filech" type="file" name="file_img[]" multiple onchange="return fileValidation()" />
Then display the images in the section below:
<div id="imagePreview"></div>
I would like to display all uploaded pictures at once instead of one by one. Can someone guide me on how to use a loop for this? Thank you in advance!