Created
November 14, 2019 14:33
-
-
Save SimonDevelop/cb0d87f5dc070a798f5d35c3fe53400a to your computer and use it in GitHub Desktop.
How to checking size file in javascript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<form method="post" enctype="multipart/form-data" onsubmit="return checkSize(2097152)"> | |
<input type="file" id="upload"> | |
<input type="submit"> | |
</form> | |
<script type="text/javascript"> | |
function checkSize(max_img_size) { | |
var input = document.getElementById("upload"); | |
if(input.files && input.files.length == 1) { | |
if (input.files[0].size > max_img_size) { | |
alert("The file must be less than " + (max_img_size/1024/1024) + "MB"); | |
return false; | |
} | |
} | |
return true; | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment