20 "application/msword" =>
"mime-wordprocessing",
21 "application/vnd.openxmlformats-officedocument.wordprocessingml.document" =>
"mime-wordprocessing",
22 "application/ogg" =>
"audio-x-generic",
23 "application/pdf" =>
"mime-pdf",
24 "application/postscript" =>
"mime-wordprocessing",
25 "application/rtf" =>
"mime-wordprocessing",
26 "application/vnd.lotus-1-2-3" =>
"mime-spreadsheet",
27 "application/vnd.ms-excel" =>
"mime-spreadsheet",
28 "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" =>
"mime-spreadsheet",
29 "application/vnd.ms-powerpoint" =>
"mime-presentation",
30 "application/vnd.oasis.opendocument.presentation" =>
"mime-presentation",
31 "application/vnd.openxmlformats-officedocument.presentationml.presentation" =>
"mime-presentation",
32 "application/vnd.oasis.opendocument.spreadsheet" =>
"mime-spreadsheet",
33 "application/vnd.oasis.opendocument.text" =>
"mime-wordprocessing",
34 "application/vnd.oasis.opendocument.graphics" =>
"mime-vectorgfx",
35 "application/vnd.stardivision.calc" =>
"mime-spreadsheet",
36 "application/vnd.stardivision.impress" =>
"mime-presentation",
37 "application/vnd.stardivision.writer" =>
"mime-wordprocessing",
38 "application/vnd.sun.xml.calc" =>
"mime-spreadsheet",
39 "application/vnd.sun.xml.impress" =>
"mime-presentation",
40 "application/vnd.sun.xml.writer" =>
"mime-wordprocessing",
41 "application/vnd.sun.xml.writer.global" =>
"mime-wordprocessing",
42 "application/vnd.sun.xml.draw" =>
"mime-vectorgfx",
43 "application/wordperfect" =>
"mime-wordprocessing",
44 "application/x-7z-compressed" =>
"mime-tgz",
45 "application/x-abiword" =>
"mime-wordprocessing",
46 "application/x-applix-spreadsheet" =>
"mime-spreadsheet",
47 "application/x-applix-word" =>
"mime-wordprocessing",
48 "application/x-archive" =>
"mime-tar",
49 "application/x-arj" =>
"mime-tgz",
50 "application/x-bzip-compressed-tar" =>
"mime-tgz",
51 "application/x-bzip" =>
"mime-tgz",
52 "application/x-compressed-tar" =>
"mime-tgz",
53 "application/x-compress" =>
"mime-tgz",
54 "application/x-cpio-compressed" =>
"mime-tgz",
55 "application/x-cpio" =>
"mime-tgz",
56 "application/x-deb" =>
"mime-tgz",
57 "application/x-dvi" =>
"mime-wordprocessing",
58 "application/x-executable" =>
"application/x-executable",
59 "application/x-font-afm" =>
"font-x-generic",
60 "application/x-font-bdf" =>
"font-x-generic",
61 "application/x-font-linux-psf" =>
"font-x-generic",
62 "application/x-font-pcf" =>
"font-x-generic",
63 "application/x-font-sunos-news" =>
"font-x-generic",
64 "application/x-font-ttf" =>
"font-x-generic",
65 "application/x-gnumeric" =>
"mime-spreadsheet",
66 "application/x-gzip" =>
"mime-tgz",
67 "application/xhtml+xml" =>
"text-html",
68 "application/x-killustrator" =>
"mime-vectorgfx",
69 "application/x-kpresenter" =>
"mime-presentation",
70 "application/x-kspread" =>
"mime-spreadsheet",
71 "application/x-kword" =>
"mime-wordprocessing",
72 "application/x-ms-dos-executable" =>
"application/x-executable",
73 "application/x-perl" =>
"mime-shellscript",
74 "application/x-php" =>
"text-html",
75 "application/x-python-bytecode" =>
"mime-shellscript",
76 "application/x-rar" =>
"mime-tgz",
77 "application/x-rpm" =>
"mime-rpm",
78 "application/x-shellscript" =>
"mime-shellscript",
79 "application/x-shockwave-flash" =>
"video-x-generic",
80 "application/x-tar" =>
"mime-tar",
81 "application/x-tarz" =>
"mime-tgz",
82 "application/x-tex" =>
"mime-tex",
83 "application/x-zip" =>
"mime-zip",
84 "application/zip" =>
"mime-zip",
85 "application" =>
"mime-zip",
86 "audio" =>
"mime-sound",
87 "image" =>
"mime-image2",
88 "video" =>
"mime-video",
89 "image/jpeg" =>
"mime-image",
90 "text/html" =>
"mime-html",
91 "text/xml" =>
"mime-xml",
92 "text/x-c++" =>
"mime-source_cpp",
93 "text/x-c" =>
"mime-source_c",
94 "text/x-c-header" =>
"mime-source_h",
95 "text/x-php" =>
"mime-source_php",
97 "text/vnd.wap.wml" =>
"mime-html",
98 "text/x-csh" =>
"mime-shellscript",
99 "text/x-python" =>
"mime-shellscript",
100 "text/x-sh" =>
"mime-shellscript",
101 "text/x-vcalendar" =>
"mime-vcalendar",
102 "text/x-vcard" =>
"mime-address-book",
103 "text/x-zsh" =>
"mime-shellscript",
104 "text/x-makefile" =>
"mime-make",
105 "x-font-afm" =>
"font-x-generic"
113 $tmime = explode(
";", $sysmime);
114 $mime = trim($tmime[0]);
116 if (isset($mimeIcon[$mime])) {
117 $icon = $mimeIcon[$mime] .
".png";
119 $p = strpos($mime,
'/');
120 $mime = substr($mime, 0, $p);
121 if (isset($mimeIcon[$mime])) {
122 $icon = $mimeIcon[$mime] .
".png";
136 if (!file_exists($f))
return false;
139 if (
$ret !==
false) {
143 $sys = trim(shell_exec(sprintf(
"file --mime -b %s", escapeshellarg($f))));
145 $sys = strtok($sys,
" ;\n\t");
147 if (preg_match(
'/Makefile/', $fn))
return 'text/x-makefile';
148 if (preg_match(
'/ASCII C\+\+/', $txt)) {
149 if (preg_match(
'/\.h$/', $fn))
return 'text/x-c-header';
152 if (preg_match(
'/PHP script/', $txt))
return 'text/x-php';
154 if (preg_match(
'/zip$/', $sys) || (preg_match(
'/octet-stream$/', $sys))) {
156 if (preg_match(
'/OpenOffice/', $txt)) {
157 if (preg_match(
'/\.sxw$/', $fn))
return 'application/vnd.sun.xml.writer';
158 if (preg_match(
'/\.sxc$/', $fn))
return 'application/vnd.sun.xml.calc';
159 if (preg_match(
'/\.sxi$/', $fn))
return 'application/vnd.sun.xml.impress';
160 if (preg_match(
'/\.sxd$/', $fn))
return 'application/vnd.sun.xml.draw';
161 if (preg_match(
'/\.sxg$/', $fn))
return 'application/vnd.sun.xml.writer.global';
162 return 'application/vnd.sun.xml.writer';
164 if (preg_match(
'/OpenDocument/', $txt)) {
165 if (preg_match(
'/\.odp$/', $fn))
return 'application/vnd.oasis.opendocument.presentation';
166 if (preg_match(
'/\.odt$/', $fn))
return 'application/vnd.oasis.opendocument.text';
167 if (preg_match(
'/\.ods$/', $fn))
return 'application/vnd.oasis.opendocument.spreadsheet';
168 if (preg_match(
'/\.odg$/', $fn))
return 'application/vnd.oasis.opendocument.graphics';
169 return 'application/vnd.oasis.opendocument.text';
172 if (preg_match(
'/\.sxw$/', $fn))
return 'application/vnd.sun.xml.writer';
173 if (preg_match(
'/\.sxc$/', $fn))
return 'application/vnd.sun.xml.calc';
174 if (preg_match(
'/\.sxi$/', $fn))
return 'application/vnd.sun.xml.impress';
175 if (preg_match(
'/\.sxd$/', $fn))
return 'application/vnd.sun.xml.draw';
176 if (preg_match(
'/\.sxg$/', $fn))
return 'application/vnd.sun.xml.writer.global';
177 if (preg_match(
'/\.odp$/', $fn))
return 'application/vnd.oasis.opendocument.presentation';
178 if (preg_match(
'/\.odt$/', $fn))
return 'application/vnd.oasis.opendocument.text';
179 if (preg_match(
'/\.ods$/', $fn))
return 'application/vnd.oasis.opendocument.spreadsheet';
180 if (preg_match(
'/\.odg$/', $fn))
return 'application/vnd.oasis.opendocument.graphics';
185 if (preg_match(
'/^XML/', $txt))
return 'text/xml';
188 if (preg_match(
'/\.xls$/', $fn))
return 'application/vnd.ms-excel';
189 if (preg_match(
'/\.doc$/', $fn))
return 'application/msword';
190 if (preg_match(
'/\.ppt$/', $fn))
return 'application/vnd.ms-powerpoint';
192 if ($sys ==
'application/msword') {
193 if (preg_match(
'/\.xls$/', $fn))
return 'application/vnd.ms-excel';
194 if (preg_match(
'/\.ppt$/', $fn))
return 'application/vnd.ms-powerpoint';
197 return strtok($sys,
" ;\n\t");
202 if (
$ret !==
false) {
206 $txt = trim(shell_exec(sprintf(
"file -b %s", escapeshellarg($f))));
207 if ($txt ==
'data') {
208 if (preg_match(
'/\.ods$/', $f)) $txt =
'OpenDocument Spreadsheet';
209 else if (preg_match(
'/\.odt$/', $f)) $txt =
'OpenDocument Text';
210 else if (preg_match(
'/\.odp$/', $f)) $txt =
'OpenDocument Presentation';
211 else if (preg_match(
'/\.odg$/', $f)) $txt =
'OpenDocument Drawing';
213 if (!$txt)
return " ";
222 include_once (
"MimeExtension.php");
224 if (!empty($exts[$smime])) {
225 return strtok($exts[$smime],
" \n\t");
246 $conf = array_merge($conf_user, $conf_global);
248 foreach ($conf as $rule) {
250 if (preg_match(
"/\.\Q$ext\E$/i",
$filename)) {
262 include_once (
'WHAT/Lib.Prefix.php');
266 $conf_file =
DEFAULT_PUBDIR . DIRECTORY_SEPARATOR .
"config" . DIRECTORY_SEPARATOR .
"mime-user.conf";
267 if (!file_exists($conf_file) || !is_readable($conf_file)) {
271 $xml = simplexml_load_file($conf_file);
272 if ($xml ===
false) {
273 error_log(__FUNCTION__ .
" " . sprintf(
"Could not load user MIME config '%s'.", $conf_file));
277 foreach ($xml->mime as $mimeNode) {
284 $rule[$attrName] = (string)$mimeNode[$attrName];
286 array_push($rules, $rule);
296 include_once (
'WHAT/Lib.Prefix.php');
300 $conf_file =
DEFAULT_PUBDIR . DIRECTORY_SEPARATOR .
"config" . DIRECTORY_SEPARATOR .
"mime.conf";
301 $xml = simplexml_load_file($conf_file);
302 if ($xml ===
false) {
303 error_log(__FUNCTION__ .
" " . sprintf(
"Could not load MIME config '%s'.", $conf_file));
307 foreach ($xml->mime as $mimeNode) {
314 $rule[$attrName] = (string)$mimeNode[$attrName];
316 array_push($rules, $rule);
328 if (file_exists(
$file)) {
329 $nbpages = intval(trim(shell_exec(sprintf(
'grep -c "/Type[[:space:]]*/Page>" %s', escapeshellarg(
$file)))));
getTextMimeFile($f, $fn= '')
getSysMimeFile($f, $fn="")
getMimeFile($filename, $type= 'sys')
getPdfNumberOfPages($file)
getIconMimeFile($sysmime)
getFileExtension($filename)