HTML输入=“文件”接受属性文件类型(CSV) [英] HTML Input="file" Accept Attribute File Type (CSV)
问题描述
我希望有人能帮助我。
I was hoping someone can help me out.
我的网页上有一个文件上传对象:
I have a file upload object on my page:
<input type="file" ID="fileSelect" />
在我的桌面上有以下excel文件:
with the following excel files on my desktop:
- file1.xlsx
- file1.xls
- file.csv
-
- file1.xlsx
- file1.xls
- file.csv
我想将文件上传到 显示 .xlsx
, .xls
,& .csv
文件。
I want the file upload to ONLY show .xlsx
, .xls
, & .csv
files.
使用 accept
属性,我发现这些内容类型处理了 .xlsx
& .xls
extensions ...
Using the accept
attribute, I found these content-types took care of .xlsx
& .xls
extensions...
code> = application / vnd.openxmlformats-officedocument.spreadsheetml.sheet(.XLSX)
accept
= application/vnd.openxmlformats-officedocument.spreadsheetml.sheet (.XLSX)
accept
= application / vnd.ms-excel(.XLS)
accept
= application/vnd.ms-excel (.XLS)
但是,我找不到Excel CSV文件的正确内容类型!有什么建议么?
However, I cannot find the correct content-type for an Excel CSV file! Any suggestions?
示例: http://jsfiddle.net/LzLcZ/
EXAMPLE: http://jsfiddle.net/LzLcZ/
推荐答案
这是令人尴尬的...我发现了我正在寻找的解决方案,它不能更简单。我使用下面的代码来获得所需的结果。希望这有助于未来的人。感谢大家的帮助。
Well this is embarrassing... I found the solution I was looking for and it couldn't be simpler. I used the following code to get the desired result. Hope this helps someone in the future. Thanks everyone for your help.
<input id="fileSelect" type="file" accept=".csv, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel" />
有效接受类型:
strong> CSV 文件(.csv),请使用:
Valid Accept Types:
For CSV files (.csv), use:
<input type="file" accept=".csv" />
对于 Excel文件97-2003 (.xls) br />
For Excel Files 97-2003 (.xls), use:
<input type="file" accept="application/vnd.ms-excel" />
对于 Excel Files 2007 + (.xlsx),请使用:
For Excel Files 2007+ (.xlsx), use:
<input type="file" accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" />
对于文本文件(.txt),请使用: / p>
For Text Files (.txt) use:
<input type="file" accept="text/plain" />
对于图片文件(.png / .jpg / etc) :
For Image Files (.png/.jpg/etc), use:
<input type="file" accept="image/*" />
对于 HTML文件(.htm,.html) br />
For HTML Files (.htm,.html), use:
<input type="file" accept="text/html" />
视频文件(.avi,.mpg,.mpeg, mp4),请使用:
For Video Files (.avi, .mpg, .mpeg, .mp4), use:
<input type="file" accept="video/*" />
对于音频文件(.mp3,.wav等) :
For Audio Files (.mp3, .wav, etc), use:
<input type="file" accept="audio/*" />
对于 PDF文件,使用:
<input type="file" accept=".pdf" />
DEMO:
http://jsfiddle.net/dirtyd77/LzLcZ/144/
注意:
如果您要显示Excel CSV档案( csv
),请 不 使用:
If you are trying to display Excel CSV files (.csv
), do NOT use:
-
text / csv
-
application / csv
-
text /逗号分隔值
(仅适用于Opera )。
text/csv
application/csv
text/comma-separated-values
(works in Opera only).
如果您尝试显示特定文件类型(例如, WAV
或 PDF
),那么这几乎总是可以工作...
If you are trying to display a particular file type (for example, a WAV
or PDF
), then this will almost always work...
<input type="file" accept=".FILETYPE" />
这篇关于HTML输入=“文件”接受属性文件类型(CSV)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!