Monday, October 21, 2013

HTML File input tag for specific file type


FILE UPLOAD

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. http://www.iana.org/assignments/media-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 : http://jsfiddle.net/LzLcZ/371/

No comments:

Post a Comment

Total Pageviews

Translate