HTML Input=“file”文件上传,限制文件类型 Accept Attribute File Type (CSV)

组合上传 CSV 和 Excel 文件:
<input id="fileSelect" type="file" accept=".csv, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel" />

有效接受类型:

对于CSV文件(.csv),请使用:
<input type="file" accept=".csv" />

对于Excel文件97-2003(.xls),请使用:
<input type="file" accept="application/vnd.ms-excel" />

对于Excel Files 2007+(.xlsx),请使用:
<input type="file" accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" />

对于文本文件(.txt),请使用:
<input type="file" accept="text/plain" />

对于图像文件(.png / .jpg / etc),请使用:
<input type="file" accept="image/*" />

对于HTML文件(.htm,.html),请使用:
<input type="file" accept="text/html" />

对于视频文件(.avi,.mpg,.mpeg,.mp4),请使用:
<input type="file" accept="video/*" />

对于音频文件(.mp3,.wav等),请使用:
<input type="file" accept="audio/*" />

对于PDF文件,请使用:
<input type="file" accept=".pdf" />

注意:
如果您试图显示Excel CSV文件(.csv),请不要使用:
text/csv
application/csv
text/comma-separated-values(仅适用于Opera)。
如果您尝试显示特定的文件类型(例如 WAV或PDF),那么这几乎总是可行的...
<input type="file" accept=".FILETYPE" />

原地址: https://stackoverflow.com/questions/11832930/html-input-file-accept-attribute-file-type-csv

猜你喜欢

转载自www.cnblogs.com/hukuangjie/p/12572685.html