如何使用javascript检查文件类型。 [英] How to check the file type using javascript.

查看:98
本文介绍了如何使用javascript检查文件类型。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要求只上传.PDF文件,它返回application / pdf mime type.But如果我只是将.txt文件的文件扩展名更改为.PDF文件然后它返回mime类型作为application / pdf并上传有没有办法安全地检查它,以便一些用户不只是上传不必要的文件。



我尝试过: < br $>


我检查了扩展名并检查了PDF文件的MIME类型。

I have a requirement to upload only.PDF file, it returns application/pdf mime type.But if I just change the file extension of .txt file to .PDF file then it returns mime type as application/pdf and getting uploaded.Is there any way to check it safely so that some user doesn't just upload unnecessary file.

What I have tried:

I checked the extension and also checked the MIME type of PDF file.

推荐答案

验证pdf文件javascript - Google搜索 [ ^ ]


我能理解,我们要么

1)检查文件扩展名或

2)检查MIME类型



我可以帮忙解决这个问题文章虽然检查文件签名。请试试。 文件签名 [ ^ ]
I could understand that, either we will
1) check the file extension or
2) check the MIME type

I could help with this article though to check the file signatures. Please try. File Signatures[^]


这篇关于如何使用javascript检查文件类型。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆