Javascript to Check File Size Before Upload Using JQuery

javascript-to-check-file-size-before-upload-using-jqueryJavascript to Check File Size Before Upload Using JQuery

cek-file-size.html :

<!-- Using jquery -->
<html>
<body>
<script src="jquery.js"></script>
<form action="upload.php" enctype="multipart/form-data" method="post">

 Upload image:
 <input id="image-file" type="file" name="file" />
 <input type="submit" value="Upload" onclick="if (eval(ukuran)>1.5) { alert('Ukuran File ' + ukuran + 'MB Melebihi Batas yaitu 1.5MB'); return false; } else { return true; }" />

 <script type="text/javascript">
 var ukuran = 0;
 $('#image-file').bind('change', function() {
 ukuran = this.files[0].size/1024/1024;
 //alert('This file size is: ' + this.files[0].size/1024/1024 + "MB");
 });
 </script>

</form>
</body>
</html>

Result :

javascript-to-check-file-size-before-upload-using-jquery

Download Source Code

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>