-1

I've been searching for answers to validate an image which is been uploaded in an html page using attributes. However, I'm only getting the answers to validate using file extensions. But I need to validate the image by any other properties.

Cause what if a person upload a text file with the file extension edited to any image file extension like text.jpeg. To avoid this I need help.

  • 3
    Possible duplicate of [How to check file MIME type with javascript before upload?](https://stackoverflow.com/questions/18299806/how-to-check-file-mime-type-with-javascript-before-upload) – Justinas Feb 21 '19 at 14:14
  • Like what propperty? the extention is normal way to look if an image is acceptable. You may wanna look at it's size (say an image below 1kb is not allowed) – Dorvalla Feb 21 '19 at 14:15
  • @Dorvalla Usually you look also to MimeType – Justinas Feb 21 '19 at 14:15

1 Answers1

0

Maybe you could check the magic numbers of the file. Here is a guide to do it in Javascript https://medium.com/the-everyday-developer/detect-file-mime-type-using-magic-numbers-and-javascript-16bc513d4e1e