How can JS or JQ get the type of uploaded file?

how to be on the front end

clipboard.png

clipboard.png

if it is image, you can get the type of file, but if it is a compressed file of zip or rar class, you can"t get type
. How should I get it?


the test should be available:

https://jsfiddle.net/jaylin00.


the function of this browser is very limited, so judge directly by intercepting the file name

however, it is impossible to judge if you manually change the suffix name of a file. For example, if a txt text is changed to jpg , you will not recognize

.

General binary files, to really determine the file type, are all through the "file header".
in your case, the browser supports header judgment of jpg and zip types, but he doesn't add rar header judgment, so he can't get type.
if the requirement is not high, you can set everything that can not get the type to "binary: application/octet-stream". If you want to be accurate, you have to read the file header and determine the file type yourself. The file type corresponding to the
file header can be found on the Internet.

Menu