A simple code snippet for checking the file-size of a file before uploading it. It will not only help to save time but also network resource as we can implement the file check at the initial point only.
The current code allows the user to select a file and then it shows an alert showing the file-size of the file after selection. The code utilizes jQuery to find the file-size.
<!DOCTYPE HTML>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js">
</script>
</head>
<body>
<form action="upload" enctype="multipart/form-data" method="post">
Upload File:
<input id="filesize" type="file" name="file" />
<input type="submit" value="Upload" />
<script type="text/javascript">
$('#filesize').bind('change', function() {
alert('This file size is: ' + this.files[0].size/1024/1024 + "MB");
});
</script>
</form>
</body>
</html>
0 Comment(s)