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

前端 未结 7 1348
有刺的猬
有刺的猬 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 09:54

    What I want to do is to check the actual file type

    Try accessing files[0].type property . See Using files from web applications

    $(":file").on("change", function(e) {
    
      console.log(this.files[0].type);
      
    })
    
    

提交回复
热议问题