移动端微信、企业微信中使用H5的input file时只能选择手机的图片,不能选择文档文件的解决方案
发表于:2025-01-16 09:52:36浏览:5530次
微信中使用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" />
推荐文章
- JavaScript 比较变量相等的奇怪现象 记录一下
- 宝塔面板查看登录地址、账号密码、运行状态和一键重启等命令
- 微信键盘正式版下载 - 融合微信生态
- webuploader简单便捷实现多个按钮上传、多个实例上传
- 最新PHP 7.4.32, PHP8.0.24 & PHP8.1.11三个分支发布了新版本
- 微软Edge浏览器在100版本里程碑之前的最后一个稳定版Edge99发布
- Thinkphp6框架Request类详解
- MySQL各类数据类型的最大长度与范围限制
- jQuery.ajax对应的post/get/delete/put请求方法封装
- 开源OA办公系统 — 勾股OA 5.6.8 新春版发布,企业办公的卓越选择

