0

I want to restrict image size while uploading. Is there any jQuery plugin to check size of uploaded image?

pimvdb
  • 151,816
  • 78
  • 307
  • 352

1 Answers1

0

Add jquery library with this and try

 <script type="text/javascript">
 function Size() {
  if ( $.browser.msie ) {
    var a = document.getElementById('file').value;
       $('#myImage').attr('src',a);
       var imgbytes = document.getElementById('Image').fileSize;
       var imgkbytes = Math.round(parseInt(imgbytes)/1024);
       alert(imgkbytes+' KB');
   }else {
       var fileInput = $("#file")[0];
       var imgbytes = fileInput.files[0].fileSize; // Size returned in bytes.
       var imgkbytes = Math.round(parseInt(imgbytes)/1024);
               alert(imgkbytes+' KB');
     }
  }    
  </script>

  <img id="Image" src="" style="display:none;"><br>
  <button onclick="Size();">Image Size</button>
  <input type="file" id="file" />
  <input type="button" value="find size" onclick="Size()" />
Avinash
  • 1,935
  • 7
  • 29
  • 55