移动端微信、企业微信中使用H5的input file时只能选择手机的图片,不能选择文档文件的解决方案
发表于:2025-01-16 09:52:36浏览:4475次
微信中使用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的遍历方法forEach和map的区别
- javascript一维数组递归排序方法
- 开源免费的个人博客软件,勾股BLOG2.0发布
- JavaScript将一个包含父子关系的扁平化数组转换成树形菜单
- window11系统,局域网无法访问本地php项目的解决方案
- Thinkphp6集成JWT API接口引入token
- 微软推出VS Code PowerShell的重大更新 PowerShell 引擎的彻底改造
- PHP根据昵称或者姓名自动生成文字头像(图片)的方法
- 又一轻量级的开源Linux服务器管理面板mdserver-web推荐
- PHP将透明图片(PNG)合并到JPG背景图片上,实现PNG透明的效果

