This post was most recently updated on August 5th, 2024
Script code:
<script src=”http://code.jquery.com/jquery-1.7.1.min.js” type=”text/javascript” > </script> <script type=”text/javascript”>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
function GetFileSize(fileid) { try { var fileSize = 0; //for IE if ($.browser.msie) { //before making an object of ActiveXObject, //please make sure ActiveX is enabled in your IE browser var objFSO = new ActiveXObject("Scripting.FileSystemObject"); var filePath = $("#" + fileid)[0].value; var objFile = objFSO.getFile(filePath); var fileSize = objFile.size; //size in kb fileSize = fileSize / 1048576; //size in mb } //for FF, Safari, Opeara and Others else { fileSize = $("#" + fileid)[0].files[0].size //size in kb fileSize = fileSize / 1048576; //size in mb } alert("Uploaded File Size is " + fileSize + "MB"); } catch (e) { alert("Error is :" + e); } } |
</script>
Html code:
1 |
<form name="upload" action=""> <input type="file" name="fUpload" id="fUpload" /> <input type="button" value="Get File Size" onclick="GetFileSize('fUpload');" /> </form> |
Demo: GetFileSize
If you have any query then drop a comment 🙂