Created
March 6, 2013 19:36
-
-
Save jacksonfdam/5102342 to your computer and use it in GitHub Desktop.
Restringir o tipo de arquivos no upload, pelo front-end.
This file contains 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
<input type="file" accept="image/jpg,image/jpeg,image/png,image/gif,image/bmp,image/tiff" /> | |
http://stackoverflow.com/questions/651700/how-to-have-jquery-restrict-file-types-on-upload | |
Ou | |
$('INPUT[type="file"]').change(function () { | |
var ext = this.value.match(/\.(.+)$/)[1]; | |
switch (ext) { | |
case 'jpg': | |
case 'jpeg': | |
case 'png': | |
case 'gif': | |
$('#uploadButton').attr('disabled', false); | |
break; | |
default: | |
alert('This is not an allowed file type.'); | |
this.value = ''; | |
} | |
}); | |
OU | |
var ext = $('#my_file_field').val().split('.').pop().toLowerCase(); | |
if($.inArray(ext, ['gif','png','jpg','jpeg']) == -1) { | |
alert('invalid extension!'); | |
} | |
OU | |
<input type="file" id="userfile" accept="image/*|video/*" required /> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment