移动端微信、企业微信中使用H5的input file时只能选择手机的图片,不能选择文档文件的解决方案
发表于:2025-01-16 09:52:36浏览:3122次
微信中使用input type=”file”做文件上传,accept属性没有限制为image,但是在微信浏览器内只能选择手机内存里的图片,不能文档等文件。经测试,在ios上只能选择图片,安卓机上有部分可以选择文档、部分只能选择图片,选择不上非图片格式的文件(默认灰色),但是在浏览器中是正常的,经过测试发现是”accept”属性的问题。
先举个简单的例子说一下:
以下这个写法在pc端是可以识别的,可以调起选择器,但在移动端是无法识别的。
<input type="file" accept=".jpg,.png,.gif"/>
移动端需要换成下面的写法就可以识别到了。
<input type="file" accept="image/jpeg,image/png,image/gif"/>
注:如果不限制图像的格式,可以写为:accept=”image/*”。
以下是移动端文件上传input=file,accept=””的一些属性(苹果,安卓):
.xls
<input type="file" accept="application/vnd.ms-excel" />
.xlsx
<input type="file" accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" />
.ppt
<input type="file" accept="application/vnd.ms-powerpoint" />
.pptx
<input type="file" accept="application/vnd.openxmlformats-officedocument.presentationml.presentation" />
.doc
<input type="file" accept="application/msword" />
.docx
<input type="file" accept="application/vnd.openxmlformats-officedocument.wordprocessingml.document" />
<input type="file" accept="application/pdf" />
.csv
<input type="file" accept=".csv" />
.png/.jpg/.jpeg/.etc
<input type="file" accept="image/*" />
.txt
<input type="file" accept="text/plain" />
.htm/.html
<input type="file" accept="text/html" />
.avi/.mpg/.mpeg/.mp4
<input type="file" accept="video/*" />
.mp3/.wav/.etc
<input type="file" accept="audio/*" />
.zip
<input type="file" accept="application/x-zip-compressed" />
以下是完整的方案:
<input type="file" accept="application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.ms-powerpoint,application/vnd.openxmlformats-officedocument.presentationml.presentation,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document,application/pdf,.csv,image/*,text/plain,video/*,audio/*,application/x-zip-compressed" />
推荐文章
- PHP中如何将数组转换为JSON格式数据
- 微软Edge浏览器在100版本里程碑之前的最后一个稳定版Edge99发布
- 勾股DEV,一款专为IT行业研发团队打造的智能化项目管理与团队协作的工具软件
- Vue又出新品——petite-vue
- ThinkPHP6使用中间件实现后台登录验证方案
- 阿里云ECS云服务器CentOS7云盘在线扩容操作
- 微软推出电脑管家,干净无广告无弹窗,是时候卸载360安全卫士和腾讯电脑管了
- 最新PHP 7.4.32, PHP8.0.24 & PHP8.1.11三个分支发布了新版本
- 开源的度量分析与可视化套件 Grafana 9正式发布
- Thinkphp6在Windows下使用Phpstudy工具升级或全局安装composer

