15 [__CLASS__,
'tryFinfo'],
16 [__CLASS__,
'tryMimeContentType'],
17 [__CLASS__,
'tryFile'],
18 [__CLASS__,
'tryGetimagesize'],
30 'txt' =>
'text/plain',
32 'html' =>
'text/html',
35 'js' =>
'application/javascript',
36 'json' =>
'application/json',
37 'xml' =>
'application/xml',
38 'swf' =>
'application/x-shockwave-flash',
39 'flv' =>
'video/x-flv',
43 'jpe' =>
'image/jpeg',
44 'jpeg' =>
'image/jpeg',
45 'jpg' =>
'image/jpeg',
48 'ico' =>
'image/vnd.microsoft.icon',
49 'tiff' =>
'image/tiff',
50 'tif' =>
'image/tiff',
51 'svg' =>
'image/svg+xml',
52 'svgz' =>
'image/svg+xml',
53 'webp' =>
'image/webp',
56 'zip' =>
'application/zip',
57 'rar' =>
'application/x-rar-compressed',
58 'exe' =>
'application/x-msdownload',
59 'msi' =>
'application/x-msdownload',
60 'cab' =>
'application/vnd.ms-cab-compressed',
63 'mp3' =>
'audio/mpeg',
64 'qt' =>
'video/quicktime',
65 'mov' =>
'video/quicktime',
68 'pdf' =>
'application/pdf',
69 'psd' =>
'image/vnd.adobe.photoshop',
70 'ai' =>
'application/postscript',
71 'eps' =>
'application/postscript',
72 'ps' =>
'application/postscript',
75 'odt' =>
'application/vnd.oasis.opendocument.text',
76 'ods' =>
'application/vnd.oasis.opendocument.spreadsheet',
79 'doc' =>
'application/msword',
80 'rtf' =>
'application/rtf',
81 'xls' =>
'application/vnd.ms-excel',
82 'ppt' =>
'application/vnd.ms-powerpoint',
83 'docx' =>
'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
84 'docm' =>
'application/vnd.ms-word.document.macroEnabled.12',
85 'dotx' =>
'application/vnd.openxmlformats-officedocument.wordprocessingml.template',
86 'dotm' =>
'application/vnd.ms-word.template.macroEnabled.12',
87 'xlsx' =>
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
88 'xlsm' =>
'application/vnd.ms-excel.sheet.macroEnabled.12',
89 'xltx' =>
'application/vnd.openxmlformats-officedocument.spreadsheetml.template',
90 'xltm' =>
'application/vnd.ms-excel.template.macroEnabled.12',
91 'xlsb' =>
'application/vnd.ms-excel.sheet.binary.macroEnabled.12',
92 'xlam' =>
'application/vnd.ms-excel.addin.macroEnabled.12',
93 'pptx' =>
'application/vnd.openxmlformats-officedocument.presentationml.presentation',
94 'pptm' =>
'application/vnd.ms-powerpoint.presentation.macroEnabled.12',
95 'ppsx' =>
'application/vnd.openxmlformats-officedocument.presentationml.slideshow',
96 'ppsm' =>
'application/vnd.ms-powerpoint.slideshow.macroEnabled.12',
97 'potx' =>
'application/vnd.openxmlformats-officedocument.presentationml.template',
98 'potm' =>
'application/vnd.ms-powerpoint.template.macroEnabled.12',
99 'ppam' =>
'application/vnd.ms-powerpoint.addin.macroEnabled.12',
100 'sldx' =>
'application/vnd.openxmlformats-officedocument.presentationml.slide',
101 'sldm' =>
'application/vnd.ms-powerpoint.slide.macroEnabled.12',
102 'one' =>
'application/msonenote',
103 'onetoc2' =>
'application/msonenote',
104 'onetmp' =>
'application/msonenote',
105 'onepkg' =>
'application/msonenote',
106 'thmx' =>
'application/vnd.ms-officetheme',
119 if (!is_file($file) || !is_readable($file)) {
123 $ext = pathinfo($file, PATHINFO_EXTENSION);
131 if ($this->use_extension && isset($this->
extensions[$ext])) {
146 foreach ($this->strategies as $strategy) {
147 $type = call_user_func($strategy, $file);
165 if (
$type ===
'application/zip') {
169 return 'application/vnd.openxmlformats-officedocument.wordprocessingml.document';
171 return 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
173 return 'application/vnd.openxmlformats-officedocument.presentationml.presentation';
179 return 'application/vnd.ms-powerpoint';
198 if (!function_exists(
'finfo_open')) {
202 $finfo = finfo_open(FILEINFO_MIME);
203 $type = finfo_file($finfo, $file);
221 return function_exists(
'mime_content_type') ? mime_content_type($file) :
'';
232 if (DIRECTORY_SEPARATOR !==
'/' || !function_exists(
'exec')) {
236 $type = @exec(
'file -b --mime-type ' . escapeshellarg($file));
248 $data = @getimagesize($file);
249 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)