input:file上傳型別控制簡單介紹

螞蟻小編發表於2017-02-27
<input type="file">可以上傳檔案,這個就不用多介紹了。

其實我們使用此控制元件可以進行上傳檔案格式的控制。

特別說明:在實際應用中,不但要在前端進行驗證,後端也是要進行驗證的。

一.此控制元件兩個主要屬性:

屬性值有以下幾個比較常用:

accept:表示可以選擇的檔案MIME型別,多個MIME型別用英文逗號分開,常用的MIME型別見下表。

multiple:是否可以選擇多個檔案,多個檔案時其value值為第一個檔案的虛擬路徑。

1.accept:

只能選擇png和gif圖片

[HTML] 純文字檢視 複製程式碼
<input id="fileId1" type="file" accept="image/png,image/gif" name="file" />

2.multiple:

多檔案上傳

[HTML] 純文字檢視 複製程式碼
<input id="fileId2" type="file" multiple="multiple" name="file" />

3.常用MIME型別:

[CSS] 純文字檢視 複製程式碼
字尾名       MIME名稱
*.3gpp    audio/3gpp, video/3gpp
*.ac3    audio/ac3
*.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    
*.jp2            image/jp2   
*.jpe       image/jpeg
*.jpeg    image/jpeg
*.jpg          image/jpeg    
*.js       text/javascript, application/javascript    
*.json    application/json    
*.mp2    audio/mpeg, video/mpeg    
*.mp3    audio/mpeg    
*.mp4    audio/mp4, video/mp4   
*.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

相關文章