jQuery how to check if uploaded file is an image without checking extensions?

前端 未结 7 1270
有刺的猬
有刺的猬 2021-01-31 09:17

Newbie here. The problem is that I currently have written a method which checks uploaded file size and extension in order to validate it. However, checking extensions is not a s

相关标签:
7条回答
  • 2021-01-31 10:05

    Here is a quick tip if you just want to know if the file is an image:

    var file = this.files[0];
    var fileType = file["type"];
    
    if (fileType.search('image') >= 0) {
      ...
    }
    
    0 讨论(0)
提交回复
热议问题