移动端微信、企业微信中使用H5的input file时只能选择手机的图片,不能选择文档文件的解决方案
发表于:2025-01-16 09:52:36浏览:2019次
微信中使用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" />
推荐文章
- Vue 3.2 刚刚发布!新的单文件组件,响应式性能大幅提升
- HTTP中GET、POST、PUT与DELETE的区别和用法
- Layui的upload模块实现多图批量上传,无需修改代码,完美解决方案
- Thinkphp8通过PhpWord导出生成word文件,支持图片处理,富文本导出完整方案
- 阿里云OSS文件上传速度技巧之内网地址上传
- Thinkphp6获取请求的模块名、类名和方法名的方式
- webuploader简单便捷实现多个按钮上传、多个实例上传
- jQuery.ajax对应的post/get/delete/put请求方法封装
- 价税合计、销项税额、发票金额 三者关系是?
- thinkphp6 leftjoin联表查询时,子表有多条记录去重后获取子表的最新记录查询方法