Getting image file size in file input field - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Image

Description

Getting image file size in file input field

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
   </head> 
   <body> 
      <script type="text/javascript">
    function handleFiles(files) {
        for (var i = 0; i < files.length; i++)
        {/*from   ww  w.j  a v  a  2 s  .c  o  m*/
            console.log(files[i].size + " Bytes");
        }
    }
    function reset() {document.getElementById('file').value = '';}

      </script> 
      <input id="file" type="file" onchange="handleFiles(this.files)" onmousedown="reset();">  
   </body>
</html>

Related Tutorials