Created
August 20, 2009 00:31
-
-
Save whalesalad/170744 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Rough method to determining a file's type based upon it's extension. | |
| // Requires jQuery | |
| function getFileType(filename) { | |
| // Get the extension of the file | |
| var extension = filename.split('.').pop().toLowerCase(); | |
| // File types and their corresponding possible extensions. | |
| var types = { | |
| 'image': ['jpg', 'jpeg', 'gif', 'png', 'bmp'], | |
| 'audio': ['wav', 'mp3', 'wma'], | |
| 'text': ['doc', 'docx', 'txt'], | |
| 'pdf': ['pdf'], | |
| 'powerpoint': ['ppt', 'pptx'], | |
| 'excel': ['xls', 'xlsx'] | |
| }; | |
| for (t in types) { | |
| // Check to see if the extension is a member of each key's array... if so, return the key. | |
| if ($.inArray(extension, types[t]) >= 0) { return t; } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment