简体   繁体   English

AngularJS HTML输入文件限制为Safari中的文件格式

[英]AngularJS HTML input file restricting to file formats in Safari

I am using below code to restrict user to upload file formats ie in upload dialogue he will be able to see only those particular files. 我正在使用下面的代码来限制用户上传文件格式,即,在上传对话框中,他将只能看到那些特定文件。

type="file" accept=".pdf,.jpg,.jpeg,.jpe,.jfif,.tif,.tiff,.doc,.docx,.xls,.xlsx,.csv" type =“ file” accept =“。pdf,.jpg,.jpeg,.jpe,.jfif,.tif,.tiff,.doc,.docx,.xls,.xlsx,.csv”

It works fine in Chrome, Mozilla and IE9 and above. 它可以在Chrome,Mozilla和IE9及更高版本中正常运行。 But this is not working in IE8 and Safari. 但这在IE8和Safari中不起作用。

How can I restrict in IE8 and Safari? 如何限制IE8和Safari?

Typically it's better to check by mime type rather than file extension, as the name of the file can be changed to anything. 通常,最好通过mime类型而不是文件扩展名进行检查,因为文件名可以更改为任何名称。 This is also the standard for the accept property. 这也是accept属性的标准。

For your example in particular, you'd want to do something like this instead: 特别是对于您的示例,您想改为执行以下操作:

<input type="file" accept="application/pdf,application/msword,application/excel,image/jpeg,image/pjpeg,image/tiff,image/x-tiff" />

If you want more flexibility, you can also do stuff like accept="image/*,video/*" to accept all image and video types. 如果您想要更大的灵活性,还可以执行诸如accept="image/*,video/*"事情来接受所有图像和视频类型。

See this page for a list of mime types and their corresponding file extensions. 请参阅此页面以获取mime类型及其相应文件扩展名的列表。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM