Newbie here. The problem is that I have currently written a method that checks the downloaded size and file extension to check it. However, checking extensions is not a solution, because such checking can cause many problems. I want to check the actual file type and check it without using the extension method. I tried using jQuery file validator , but to no avail ... This is a snippet from my current code:
<input type='file' id='imageLoader' name='imageLoader' accept="image/*" data-type='image' />
Script:
App.Dispatcher.on("uploadpic", function() { $(":file").change(function() { if (this.files && this.files[0] && this.files[0].name.match(/\.(jpg|jpeg|png|gif)$/) ) { if(this.files[0].size>1048576) { alert('File size is larger than 1MB!'); } else { var reader = new FileReader(); reader.onload = imageIsLoaded; reader.readAsDataURL(this.files[0]); } } else alert('This is not an image file!'); }); function imageIsLoaded(e) { result = e.target.result; $('#image').attr('src', result); }; });
It is called after changing the input and after checking its loading and displaying the image. So far, I only care about checking, and any help or ideas would be greatly appreciated!
javascript jquery validation
Acallar
source share