Client Checking file size using HTML5

HTMLWeb DevelopmentFront End Technology

Before HTML5, the file size was checked with flash but now flash is avoided in web apps. Still the file size on the client side can be checked by inserting the below given code inside an event listener.

if (typeofFileReader !== "undefined") {
   // file[0] is file 1
   var s = document.getElementById('myfile').files[0].size;

On file input change, the size will update. For that, use event listener,

document.getElementById('input').onchange = function() {
   // file[0] is file 1
   var s = document.getElementById('input').files[0].size;
Updated on 04-Mar-2020 05:02:06