I want to restrict image size while uploading. Is there any jQuery plugin to check size of uploaded image?
Asked
Active
Viewed 1,818 times
1 Answers
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