Is there any Jquery plugin that will restrict a HT

2019-08-18 11:42发布

问题:

I saw a lot of file up loader plugins .I dont want to use the entire file upload plugin ..

Means , I am using my own code. But i didnt find a way to restrict the file type the uploader accepts .. How can i do that? . Is there any plugin which doing only this function ( I don't want to use a full file uploader plugin)

回答1:

This requires HTML5, jQuery is not needed. I think it will be small enough to use pure JavaScript:

  • first you can set the accept attribute to image/*
  • after that you can use the File Api to read the first bytes for the magic number - image numbers demo

These are just some ideas. You can devise some heuristic to check the file type based on this.