Skip to content

Instantly share code, notes, and snippets.

@rozklad
Last active August 29, 2015 14:18
Show Gist options
  • Save rozklad/66d9f86c0116465360ea to your computer and use it in GitHub Desktop.
Save rozklad/66d9f86c0116465360ea to your computer and use it in GitHub Desktop.
Turn MIME type into font awesome file icon name (e.g. file-text-o)
<?php
/**
* Turn mimetype into font awesome file icon name (e.g. file-text-o)
* @param string $mimetype File mimetype
* @return string Font Awesome file icon name
*/
function mimetype2FontAwesome($mimetype = null) {
switch( $mimetype ) {
// PDF
case 'application/pdf':
return 'file-pdf-o';
break;
// Plain text
case 'text/plain':
return 'file-text-o';
break;
// Audio
case 'audio/basic':
case 'audio/L24':
case 'audio/mp4':
case 'audio/mpeg':
case 'audio/ogg':
case 'audio/flac':
case 'audio/opus':
case 'audio/vorbis':
case 'audio/vnd.rn-realaudio':
case 'audio/vnd.wave':
case 'audio/webm':
case 'audio/x-aac':
case 'audio/x-caf':
return 'file-audio-o';
break;
// Video
case 'video/avi':
case 'video/mpeg':
case 'video/mp4':
case 'video/ogg':
case 'video/quicktime':
case 'video/webm':
case 'video/x-matroska':
case 'video/x-ms-wmv':
case 'video/x-fkv':
return 'file-video-o';
break;
// Powerpoint
case 'application/vnd.ms-powerpoint':
case 'application/vnd.openxmlformats-officedocument.presentationml.presentation':
case 'application/vnd.openxmlformats-officedocument.presentationml.template':
case 'application/vnd.openxmlformats-officedocument.presentationml.slideshow':
case 'application/vnd.ms-powerpoint.addin.macroEnabled.12':
case 'application/vnd.ms-powerpoint.presentation.macroEnabled.12':
case 'application/vnd.ms-powerpoint.template.macroEnabled.12':
case 'application/vnd.ms-powerpoint.slideshow.macroEnabled.12':
return 'file-powerpoint-o';
break;
// Word
case 'application/msword':
case 'application/vnd.openxmlformats-officedocument.wordprocessingml.template':
case 'application/vnd.openxmlformats-officedocument.wordprocessingml.document':
case 'application/vnd.ms-word.document.macroEnabled.12':
case 'application/vnd.ms-word.template.macroEnabled.12':
return 'file-word-o';
break;
// Excel
case 'application/vnd.ms-excel':
case 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet':
case 'application/vnd.openxmlformats-officedocument.spreadsheetml.template':
case 'application/vnd.ms-excel.sheet.macroEnabled.12':
case 'application/vnd.ms-excel.template.macroEnabled.12':
case 'application/vnd.ms-excel.addin.macroEnabled.12':
case 'application/vnd.ms-excel.sheet.binary.macroEnabled.12':
case 'text/csv':
return 'file-excel-o';
break;
case 'application/json':
case 'application/javascript':
case 'application/xhtml+xml':
case 'application/xml':
case 'text/xml':
case 'text/javascript':
case 'text/html':
case 'text/cmd':
case 'text/css':
case 'text/vcard':
case 'text/x-markdown':
case 'text/x-jquery-tmpl':
return 'file-code-o';
break;
// Archive
case 'application/x-rar-compressed':
case 'application/x-7z-compressed':
case 'application/zip':
case 'application/gzip':
return 'file-archive-o';
break;
// Image
case 'image/gif':
case 'image/jpeg':
case 'image/png':
case 'image/bmp':
case 'image/svg+xml':
case 'image/tiff':
case 'image/vnd.djvu':
case 'image/x-xcf':
return 'file-image-o';
break;
// All the others
default:
return 'file';
break;
}
}
?>
<!-- Sample usage -->
<i class="fa fa-<?php echo mimetype2FontAwesome('application/zip'); ?>"></i>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment