Last active
October 13, 2022 09:30
-
-
Save guedressel/0daa170c0fde65ce5551 to your computer and use it in GitHub Desktop.
Font Awesome File Icons: Mapping MIME Types to correct icon classes
This file contains 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
<?php | |
/** | |
* Get font awesome file icon class for specific MIME Type | |
* @see https://gist.github.com/guedressel/0daa170c0fde65ce5551 | |
* | |
*/ | |
function font_awesome_file_icon_class( $mime_type ) { | |
// List of official MIME Types: http://www.iana.org/assignments/media-types/media-types.xhtml | |
static $font_awesome_file_icon_classes = array( | |
// Images | |
'image' => 'fa-file-image-o', | |
// Audio | |
'audio' => 'fa-file-audio-o', | |
// Video | |
'video' => 'fa-file-video-o', | |
// Documents | |
'application/pdf' => 'fa-file-pdf-o', | |
'text/plain' => 'fa-file-text-o', | |
'text/html' => 'fa-file-code-o', | |
'application/json' => 'fa-file-code-o', | |
// Archives | |
'application/gzip' => 'fa-file-archive-o', | |
'application/zip' => 'fa-file-archive-o', | |
// Misc | |
'application/octet-stream' => 'fa-file-o', | |
); | |
if (isset($font_awesome_file_icon_classes[ $mime_type ])) { | |
return $font_awesome_file_icon_classes[ $mime_type ]; | |
} | |
$mime_parts = explode('/', $mime_type, 2); | |
$mime_group = $mime_parts[0]; | |
if (isset($font_awesome_file_icon_classes[ $mime_group ])) { | |
return $font_awesome_file_icon_classes[ $mime_group ]; | |
} | |
return "fa-file-o"; | |
} |
Excellent work, thank you. I used your code as inspiration to build a gist to map filenames (using the extension) to Font Awesome classes.
https://gist.github.com/DigitalLeaves/414365b686f7991af9d4fb9bdcc4cc4e
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I updated your function to current Fontawesome 5.6 icons