HTML文件输入仅接受.zip文件(不接受.exe) [英] HTML file input accept only .zip files (not .exe)

查看:162
本文介绍了HTML文件输入仅接受.zip文件(不接受.exe)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将此用于我的文件输入中的accept字段:

using this for the accept field in my file input:

application/zip,application/x-zip,application/x-zip-compressed,application/octet-stream

结果:

  • Internet Explorer:仅显示.zip.是的.
  • FireFox:显示所有文件,但我可以将下拉列表更改为仅显示.zip.我可以通过某种方式将.zip更改为默认视图吗?
  • Chrome:显示.zip和.exe.如何排除.exe?

我知道chrome在技术上是正确的,但是我想在这里做到用户友好.

I know chrome is technically right, but I'm trying to be user friendly here.

推荐答案

application/octet-stream是包罗万象"存储桶.如果文件名没有扩展名来帮助确定它,则它是默认的mime类型.我猜这也是您的EXE在Chrome中的表示形式.

application/octet-stream is the "catch-all" bucket. It's the default mime-type if the filename has no extension to help determine it. It's also the source of your EXE representation in Chrome, I'm guessing.

使用< input type ="file" ;> ;?

您也可以尝试使用INPUT/File上的"accept"属性来减少它.上面的链接还有指向您可以播放和测试的JSFiddle页面的链接.

You can also try reducing it with the "accept" attribute on the INPUT/File. That link above also has a link to a JSFiddle page you can play and test with.

这篇关于HTML文件输入仅接受.zip文件(不接受.exe)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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