<input type="file">可以上传文件,这个就不用多介绍了。
其实我们使用此控件可以进行上传文件格式的控制。
特别说明:在实际应用中,不但要在前端进行验证,后端也是要进行验证的。
一.此控件两个主要属性:
属性值有以下几个比较常用:
accept:表示可以选择的文件MIME类型,多个MIME类型用英文逗号分开,常用的MIME类型见下表。
multiple:是否可以选择多个文件,多个文件时其value值为第一个文件的虚拟路径。
1.accept:
只能选择png和gif图片
1
|
<
input
id
=
"fileId1"
type
=
"file"
accept
=
"image/png,image/gif"
name
=
"file"
/>
|
2.multiple:
多文件上传
1
|
<
input
id
=
"fileId2"
type
=
"file"
multiple
=
"multiple"
name
=
"file"
/>
|
3.常用MIME类型:
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
后缀名 MIME名称
*.
3
gpp audio/
3
gpp, video/
3
gpp
*.ac
3
audio/ac
3
*.asf allpication/vnd.ms-asf
*.au audio/basic
*.css text/css
*.csv text/csv
*.doc application/msword
*.dot application/msword
*.dtd application/xml-dtd
*.dwg image/vnd.dwg
*.dxf image/vnd.dxf
*.gif image/gif
*.htm text/html
*.html text/html
*.jp
2
image/jp
2
*.jpe image/jpeg
*.jpeg image/jpeg
*.jpg image/jpeg
*.js text/javascript, application/javascript
*.json application/json
*.mp
2
audio/mpeg, video/mpeg
*.mp
3
audio/mpeg
*.mp
4
audio/mp
4
, video/mp
4
*.mpeg video/mpeg
*.mpg video/mpeg
*.mpp application/vnd.ms-project
*.ogg application/ogg, audio/ogg
*.pdf application/pdf
*.png image/png
*.pot application/vnd.ms-powerpoint
*.pps application/vnd.ms-powerpoint
*.ppt application/vnd.ms-powerpoint
*.rtf application/rtf, text/rtf
*.svf image/vnd.svf
*.tif image/tiff
*.tiff image/tiff
*.txt text/plain
*.wdb application/vnd.ms-works
*.wps application/vnd.ms-works
*.xhtml application/xhtml+xml
*.xlc application/vnd.ms-excel
*.xlm application/vnd.ms-excel
*.xls application/vnd.ms-excel
*.xlt application/vnd.ms-excel
*.xlw application/vnd.ms-excel
*.xml text/xml, application/xml
*.zip aplication/zip
|
原文发布时间为:2017-2-27
本文作者:admin
本文来自云栖社区合作伙伴“蚂蚁部落”,了解相关信息可以关注蚂蚁部落
原文链接:input:file上传类型控制简单介绍