Find fileupload control selected file size using jquery
This example shows you how to find the fileupload control selected file size using jquery.
Example:Code:
$(document).ready(function () {
$('#fupexample').bind('change', function () {
var size = this.files[0].size;
var str = "File Size:\n" + size + " Bytes";
str += "\n" + (size / 1024).toFixed(2) + " KB";
str += "\n" + ((size / 1024) / 1024).toFixed(2) + " MB";
alert(str);
});
});
Source Code:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script src="http://code.jquery.com/jquery-1.10.2.js"></script>
<script language="javascript">
$(document).ready(function () {
$('#fupexample').bind('change', function () {
var size = this.files[0].size;
var str = "File Size:\n" + size + " Bytes";
str += "\n" + (size / 1024).toFixed(2) + " KB";
str += "\n" + ((size / 1024) / 1024).toFixed(2) + " MB";
alert(str);
});
});
</script>
</head>
<body>
<input type="file" id="fupexample" name="fupexample" style="width: 200px;" />
</body>
</html>
Useful Tools
Online Code Editor and Compiler
HTML Minifier
Online HTML Compiler/Preivew
Word Count Tool
Replace Text/Word tool
Latest Blogs
How to check if a canvas is empty or blank
Maintain div or panel scroll position after postback in asp.net update panel
Draggable button using jquery ui
Get total number of tables, views, stored procedures and functions count and names in sql server
JavaScript function to get date in mmddyyyy hhmmss ampm forma