Is HttpPostedFile.ContentType a flawless way to validate an uploaded file?

前端 未结 3 1709
太阳男子
太阳男子 2020-12-19 05:42

I want to validate the file type to make sure the user is uploading an image of type JPEG, GIF, or PNG. Instead of checking the file extension, I figured using HttpPostedFil

3条回答
  •  攒了一身酷
    2020-12-19 06:14

    To reliably know the content type, you might want to look into Content Type sniffing, for instance:

    http://suika.fam.cx/www/markup/html/whatpm/Whatpm/ContentType.html

    This tries to determine the content type of the file by examining the first few bytes.

提交回复
热议问题