My english is not that good sorry...
hi i am working on a project where i have to upload diff types of files across my web app(MVC 5). i want to only allow the user to upload the file which is predifined. like if it is image only image can get uploaded and so on.
i have done this using custom validator and it works fine but i and also checked it while uplaoding
$("#FilUploader").change(function() {
var fileExtension = ['jpeg', 'jpg', 'png', 'gif', 'bmp'];
if ($.inArray($(this).val().split('.').pop().toLowerCase(), fileExtension) == -1) {
alert("Only Images are allowed : " + fileExtension.join(', '));
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<input type="file" accept="image/x-png,image/gif,image/jpeg,image/jpg" name="ImageUpload"id="FilUploader" />
like this but after the above javascript it will still upload the file in my model property which i have to check in my custom validator.
i also accept parameter in html but this is useless as it can be changed
i want something that wont allow the user to upload any other file and remove it in window itself
i don't want to use $('#file').val('')
Please help thanks in advance