Monday, October 21, 2013

HTML File input tag for specific file type


Sometimes we may need to specify the exact file type for upload/select.
This is one way to handle that.

Using File Extension(Here .csv is using. You can use any extension like .jar, .ppt etc.)
<input type="file" name="pic" id="pic" accept=".csv" />

Using File Type
<input type="file" name="pic" id="pic" accept="text/plain" />
You can use this link to find out the file types.

For selecting video files only
<input type="file" name="pic" id="pic" accept="video/*" />

For selecting audio files only
<input type="file" name="pic" id="pic" accept="audio/*" />

For   Excel Files 2010 (.xlsx) 
<input type="file" accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" />

Here is the Working Example :

No comments:

Post a Comment

Total Pageviews