Skip to content

Instantly share code, notes, and snippets.

@hacheraw
Created January 31, 2021 21:38
Show Gist options
  • Save hacheraw/ffd64542fad6468356d60d5f0203a335 to your computer and use it in GitHub Desktop.
Save hacheraw/ffd64542fad6468356d60d5f0203a335 to your computer and use it in GitHub Desktop.
Mimetype to fontAwesome mapping

Mimetype to fontAwesome

Some of them are mapped to just a regular "file" icon.

/**
* Devuelve un icono de fontAwesome correspondiente a un MimeType
*
* @param string $mimetype por ejemplo 'image/jpeg'
* @param string $class clases extras del icono
* @param string $style tipo de icono: fas, far...
* @return string
*/
function fileIcon(string $mimetype, string $extraClass = '', string $style = 'far'): string
{
$classes = [
'image/jpeg' => 'file-image',
'image/gif' => 'file-image',
'image/png' => 'file-image',
'image/bmp' => 'file-image',
'image/tiff' => 'file-image',
'image/x-icon' => 'file-image',
'video/x-ms-asf' => 'file-video',
'video/x-ms-wmv' => 'file-video',
'video/x-ms-wmx' => 'file-video',
'video/x-ms-wm' => 'file-video',
'video/avi' => 'file-video',
'video/divx' => 'file-video',
'video/x-flv' => 'file-video',
'video/quicktime' => 'file-video',
'video/mpeg' => 'file-video',
'video/mp4' => 'file-video',
'video/ogg' => 'file-video',
'video/webm' => 'file-video',
'video/x-matroska' => 'file-video',
'video/3gpp' => 'file-video',
'video/3gpp2' => 'file-video',
'text/plain' => 'file-alt',
'text/csv' => 'file-alt',
'text/tab-separated-values' => 'file-alt',
'text/calendar' => 'file-alt',
'text/richtext' => 'file-alt',
'text/html' => 'file-alt',
'text/vtt' => 'file-alt',
'application/ttaf+xml' => 'file-code',
'audio/mpeg' => 'file-audio',
'audio/aac' => 'file-audio',
'audio/x-realaudio' => 'file-audio',
'audio/wav' => 'file-audio',
'audio/ogg' => 'file-audio',
'audio/flac' => 'file-audio',
'audio/midi' => 'file-audio',
'audio/x-ms-wma' => 'file-audio',
'audio/x-ms-wax' => 'file-audio',
'audio/x-matroska' => 'file-audio',
'application/rtf' => 'file-alt',
'application/pdf' => 'file-pdf',
'application/x-tar' => 'file-archive',
'application/zip' => 'file-archive',
'application/x-gzip' => 'file-archive',
'application/rar' => 'file-archive',
'application/x-7z-compressed' => 'file-archive',
'application/octet-stream' => 'file-code',
'application/octet-stream' => 'file-code',
'application/msword' => 'file-word',
'application/vnd.ms-powerpoint' => 'file-powerpoint',
'application/vnd.ms-write' => 'file-word',
'application/vnd.ms-excel' => 'file-excel',
'application/vnd.ms-access' => 'file',
'application/vnd.ms-project' => 'file',
'application/vnd.openxmlformats-officedocument.wordprocessingml.document' => 'file-word',
'application/vnd.ms-word.document.macroEnabled.12' => 'file-word',
'application/vnd.openxmlformats-officedocument.wordprocessingml.template' => 'file-word',
'application/vnd.ms-word.template.macroEnabled.12' => 'file-word',
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' => 'file-excel',
'application/vnd.ms-excel.sheet.macroEnabled.12' => 'file-excel',
'application/vnd.ms-excel.sheet.binary.macroEnabled.12' => 'file-excel',
'application/vnd.openxmlformats-officedocument.spreadsheetml.template' => 'file-excel',
'application/vnd.ms-excel.template.macroEnabled.12' => 'file-excel',
'application/vnd.ms-excel.addin.macroEnabled.12' => 'file-excel',
'application/vnd.openxmlformats-officedocument.presentationml.presentation' => 'file-powerpoint',
'application/vnd.ms-powerpoint.presentation.macroEnabled.12' => 'file-powerpoint',
'application/vnd.openxmlformats-officedocument.presentationml.slideshow' => 'file-powerpoint',
'application/vnd.ms-powerpoint.slideshow.macroEnabled.12' => 'file-powerpoint',
'application/vnd.openxmlformats-officedocument.presentationml.template' => 'file-powerpoint',
'application/vnd.ms-powerpoint.template.macroEnabled.12' => 'file-powerpoint',
'application/vnd.ms-powerpoint.addin.macroEnabled.12' => 'file-powerpoint',
'application/vnd.openxmlformats-officedocument.presentationml.slide' => 'file-powerpoint',
'application/vnd.ms-powerpoint.slide.macroEnabled.12' => 'file-powerpoint',
'application/onenote' => 'file-alt',
'application/oxps' => 'file-alt',
'application/vnd.ms-xpsdocument' => 'file-alt',
'application/vnd.oasis.opendocument.text' => 'file-word',
'application/vnd.oasis.opendocument.presentation' => 'file-powerpoint',
'application/vnd.oasis.opendocument.spreadsheet' => 'file-excel',
'application/vnd.oasis.opendocument.graphics' => 'file',
'application/vnd.oasis.opendocument.chart' => 'file',
'application/vnd.oasis.opendocument.database' => 'file',
'application/vnd.oasis.opendocument.formula' => 'file',
'application/wordperfect' => 'file-word',
'application/vnd.apple.keynote' => 'file-powerpoint',
'application/vnd.apple.numbers' => 'file-excel',
'application/vnd.apple.pages' => 'file'
];
$class = $classes[$mimetype] ?? 'file';
if (!empty($extraClass)) {
$class .= ` {$extraClass}`;
}
return `<i class="{$style} fa-{$class}"></i>`;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment