Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save mikhy888/d56db0c0e85bd927a3552b34ce0cdb9c to your computer and use it in GitHub Desktop.
Save mikhy888/d56db0c0e85bd927a3552b34ce0cdb9c to your computer and use it in GitHub Desktop.
<!--here is the html-->
<input id="txt" type = "text" value = "Choose File" onclick ="javascript:document.getElementById('file').click();">
<input id = "file" class="upload-opt" type="file" style='display: none;' name="upload"/>
<!--here is the script-->
$('#file').on( 'change', function() {
var myfile= $( this ).val();
var ext = myfile.split('.').pop();
//alert(ext);
if(ext=="pdf" || ext=="docx" || ext=="doc" || ext=="txt" || ext=="odc" || ext=="jpg" ){
if(this.files[0].size > 1048576){
$('.upload-opt').next('.validation-text').text('File is too big!');
this.value = "";
} else {
var value = $(this).val();
$("#txt").val(value);
}
} else {
$('.upload-opt').next('.validation-text').text('This kind of file cant be uploaded');
this.value = "";
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment