I have an input to upload files which successfully validates if the inserted files are of ".jpeg" or ".pdf" type of extension. However, it doesn't validate the file's content to check if it actually matches those type of extensions. In other words, i can grab a file that isn't ".jpeg" or ".pdf", change it's extension to one of those types and upload it. How can i avoid this scenario?
Asked
Active
Viewed 616 times
0
-
2maybe this can help - https://stackoverflow.com/questions/772388/c-sharp-how-can-i-test-a-file-is-a-jpeg – Piyush Khanna Sep 06 '18 at 15:36
-
2JPEG files can be read as a byte[]. Its first two bytes are FF D8 and last FF D9. With PDFs it's: 25 50 44 46, which translates to `%PDF` in ASCII. (see https://stackoverflow.com/questions/6186980/determine-if-a-byte-is-a-pdf-file) – jAC Sep 06 '18 at 15:37
-
3Possible duplicate of [C# How can I test a file is a jpeg?](https://stackoverflow.com/questions/772388/c-sharp-how-can-i-test-a-file-is-a-jpeg) – Andrew Morton Sep 06 '18 at 15:48