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>