Skip to content

Instantly share code, notes, and snippets.

@spsaucier
Last active December 20, 2015 00:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save spsaucier/6044072 to your computer and use it in GitHub Desktop.
Save spsaucier/6044072 to your computer and use it in GitHub Desktop.
Disallow large file uploads
// Disallows uploads over 2Mb
$(document).on('change', 'input[type=file]', function() {
//this.files[0].size gets the size of your file.
if (this.files[0].size > 2097152 || this.files[0].filesize > 2097152) {
alert('Your file is too large (over 2Mb). Please use a smaller file.')
$(this).wrap('<form>').closest('form').get(0).reset();
$(this).unwrap();
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment