jQuery File size validations. Arrow functions for file size validations.
Filevalidation = () => {
document.getElementById('size').innerHTML = '';
let fi = document.getElementById('files');
// Check if any file is selected.
if (fi.files.length > 0) {
for (const i = 0; i <= fi.files.length - 1; i++) {
const fsize = fi.files.item(i).size;
const file = Math.round((fsize / 1024));
// The size of the file.
if (file >= 4096) {
alert(
"File too Big, please select a file less than 4mb");
document.getElementById('files').value = '';
} else if (file <= 1 ) {
alert(
"File too small, please select a file greater than 1KB");
} else {
document.getElementById('size').innerHTML = '<b>'
+ file + '</b> KB';
}
}
}
}
No comments:
Post a Comment