15 [__CLASS__,
'tryFinfo'],
16 [__CLASS__,
'tryMimeContentType'],
17 [__CLASS__,
'tryFile'],
18 [__CLASS__,
'tryGetimagesize'],
30 'txt' =>
'text/plain',
32 'html' =>
'text/html',
35 'js' =>
'text/javascript',
36 'mjs' =>
'text/javascript',
37 'json' =>
'application/json',
38 'xml' =>
'application/xml',
39 'swf' =>
'application/x-shockwave-flash',
40 'flv' =>
'video/x-flv',
44 'jpe' =>
'image/jpeg',
45 'jpeg' =>
'image/jpeg',
46 'jpg' =>
'image/jpeg',
49 'ico' =>
'image/vnd.microsoft.icon',
50 'tiff' =>
'image/tiff',
51 'tif' =>
'image/tiff',
52 'svg' =>
'image/svg+xml',
53 'svgz' =>
'image/svg+xml',
54 'webp' =>
'image/webp',
57 'zip' =>
'application/zip',
58 'rar' =>
'application/x-rar-compressed',
59 'exe' =>
'application/x-msdownload',
60 'msi' =>
'application/x-msdownload',
61 'cab' =>
'application/vnd.ms-cab-compressed',
64 'mp3' =>
'audio/mpeg',
65 'qt' =>
'video/quicktime',
66 'mov' =>
'video/quicktime',
69 'pdf' =>
'application/pdf',
70 'psd' =>
'image/vnd.adobe.photoshop',
71 'ai' =>
'application/postscript',
72 'eps' =>
'application/postscript',
73 'ps' =>
'application/postscript',
76 'odt' =>
'application/vnd.oasis.opendocument.text',
77 'ods' =>
'application/vnd.oasis.opendocument.spreadsheet',
80 'doc' =>
'application/msword',
81 'rtf' =>
'application/rtf',
82 'xls' =>
'application/vnd.ms-excel',
83 'ppt' =>
'application/vnd.ms-powerpoint',
84 'docx' =>
'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
85 'docm' =>
'application/vnd.ms-word.document.macroEnabled.12',
86 'dotx' =>
'application/vnd.openxmlformats-officedocument.wordprocessingml.template',
87 'dotm' =>
'application/vnd.ms-word.template.macroEnabled.12',
88 'xlsx' =>
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
89 'xlsm' =>
'application/vnd.ms-excel.sheet.macroEnabled.12',
90 'xltx' =>
'application/vnd.openxmlformats-officedocument.spreadsheetml.template',
91 'xltm' =>
'application/vnd.ms-excel.template.macroEnabled.12',
92 'xlsb' =>
'application/vnd.ms-excel.sheet.binary.macroEnabled.12',
93 'xlam' =>
'application/vnd.ms-excel.addin.macroEnabled.12',
94 'pptx' =>
'application/vnd.openxmlformats-officedocument.presentationml.presentation',
95 'pptm' =>
'application/vnd.ms-powerpoint.presentation.macroEnabled.12',
96 'ppsx' =>
'application/vnd.openxmlformats-officedocument.presentationml.slideshow',
97 'ppsm' =>
'application/vnd.ms-powerpoint.slideshow.macroEnabled.12',
98 'potx' =>
'application/vnd.openxmlformats-officedocument.presentationml.template',
99 'potm' =>
'application/vnd.ms-powerpoint.template.macroEnabled.12',
100 'ppam' =>
'application/vnd.ms-powerpoint.addin.macroEnabled.12',
101 'sldx' =>
'application/vnd.openxmlformats-officedocument.presentationml.slide',
102 'sldm' =>
'application/vnd.ms-powerpoint.slide.macroEnabled.12',
103 'one' =>
'application/msonenote',
104 'onetoc2' =>
'application/msonenote',
105 'onetmp' =>
'application/msonenote',
106 'onepkg' =>
'application/msonenote',
107 'thmx' =>
'application/vnd.ms-officetheme',
120 if (!is_file($file) || !is_readable($file)) {
124 $ext = pathinfo($file, PATHINFO_EXTENSION);
132 if ($this->use_extension && isset($this->
extensions[$ext])) {
147 foreach ($this->strategies as $strategy) {
148 $type = call_user_func($strategy, $file);
166 if (
$type ===
'application/zip') {
170 return 'application/vnd.openxmlformats-officedocument.wordprocessingml.document';
172 return 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
174 return 'application/vnd.openxmlformats-officedocument.presentationml.presentation';
180 return 'application/vnd.ms-powerpoint';
184 if (
$type ===
'text/plain' && in_array(
$extension, [
'css',
'js',
'mjs'])) {
204 if (!function_exists(
'finfo_open')) {
208 $finfo = finfo_open(FILEINFO_MIME);
209 $type = finfo_file($finfo, $file);
227 return function_exists(
'mime_content_type') ? mime_content_type($file) :
'';
238 if (DIRECTORY_SEPARATOR !==
'/' || !function_exists(
'exec')) {
242 $type = @exec(
'file -b --mime-type ' . escapeshellarg($file));
254 $data = @getimagesize($file);
255 return empty(
$data[
'mime']) ?
'' :
$data[
'mime'];
static tryGetimagesize($file)
Detect MIME type.
tryStrategies($file)
Detect MIME type using various strategies.
static tryFinfo($file)
Detect MIME type using finfo_open.
if(!$entity instanceof\ElggUser) $data
getType($file, $default=self::DEFAULT_TYPE)
Sniff the MIME type.
fixDetectionErrors($type, $extension)
Fix common type detection errors.
static tryMimeContentType($file)
Detect MIME type using mime_content_type.
Detect the MIME type of a file.
static tryFile($file)
Detect MIME type using file(1)