ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f870
All Data Structures Namespaces Files Functions Variables Modules Pages
ilMimeTypeUtil Class Reference

Mime type determination. More...

+ Collaboration diagram for ilMimeTypeUtil:

Static Public Member Functions

static getMimeType ($a_file="", $a_filename="", $a_mime="")
 Get Mime type. More...
 
static getExt2MimeMap ()
 get file extension to mime type map More...
 

Detailed Description

Mime type determination.

Author
Alex Killing alex..nosp@m.kill.nosp@m.ing@g.nosp@m.mx.d.nosp@m.e
Version
$Id$

Definition at line 12 of file class.ilMimeTypeUtil.php.

Member Function Documentation

◆ getExt2MimeMap()

static ilMimeTypeUtil::getExt2MimeMap ( )
static

get file extension to mime type map

Definition at line 89 of file class.ilMimeTypeUtil.php.

Referenced by getMimeType(), ilObjMediaCastGUI\ilObjMediaCastGUI(), and ilMediaCastSettings\initStorage().

90  {
91  // for office, see http://stackoverflow.com/questions/4212861/what-is-a-correct-mime-type-for-docx-pptx-etc
92  $types_map = array (
93  '.3gp' => 'video/3gpp',
94  '.a' => 'application/octet-stream',
95  '.ai' => 'application/postscript',
96  '.aif' => 'audio/x-aiff',
97  '.aifc' => 'audio/x-aiff',
98  '.aiff' => 'audio/x-aiff',
99  '.asd' => 'application/astound',
100  '.asf' => 'video/x-ms-asf',
101  '.asn' => 'application/astound',
102  '.asx' => 'video/x-ms-asf',
103  '.au' => 'audio/basic',
104  '.avi' => 'video/x-msvideo',
105  '.bat' => 'text/plain',
106  '.bcpio' => 'application/x-bcpio',
107  '.bin' => 'application/octet-stream',
108  '.bmp' => 'image/x-ms-bmp',
109  '.c' => 'text/plain',
110  '.cdf' => 'application/x-cdf',
111  '.class' => 'application/x-java-applet',
112  '.com' => 'application/octet-stream',
113  '.cpio' => 'application/x-cpio',
114  '.csh' => 'application/x-csh',
115  '.css' => 'text/css',
116  '.csv' => 'text/comma-separated-values',
117  '.dcr' => 'application/x-director',
118  '.dir' => 'application/x-director',
119  '.dll' => 'application/octet-stream',
120  '.doc' => 'application/msword',
121  '.docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
122  '.dot' => 'application/msword',
123  '.dotx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.template',
124  '.dvi' => 'application/x-dvi',
125  '.dwg' => 'application/acad',
126  '.dxf' => 'application/dxf',
127  '.dxr' => 'application/x-director',
128  '.eml' => 'message/rfc822',
129  '.eps' => 'application/postscript',
130  '.etx' => 'text/x-setext',
131  '.exe' => 'application/octet-stream',
132  '.flv' => 'video/x-flv',
133  '.gif' => 'image/gif',
134  '.gtar' => 'application/x-gtar',
135  '.gz' => 'application/gzip',
136  '.h' => 'text/plain',
137  '.hdf' => 'application/x-hdf',
138  '.htm' => 'text/html',
139  '.html' => 'text/html',
140  '.ief' => 'image/ief',
141  '.iff' => 'image/iff',
142  '.jar' => 'application/x-java-applet',
143  '.jpe' => 'image/jpeg',
144  '.jpeg' => 'image/jpeg',
145  '.jpg' => 'image/jpeg',
146  '.js' => 'text/javascript',
147  '.ksh' => 'text/plain',
148  '.latex' => 'application/x-latex',
149  '.m1v' => 'video/mpeg',
150  '.man' => 'application/x-troff-man',
151  '.me' => 'application/x-troff-me',
152  '.mht' => 'message/rfc822',
153  '.mhtml' => 'message/rfc822',
154  '.mid' => 'audio/x-midi',
155  '.midi' => 'audio/x-midi',
156  '.mif' => 'application/x-mif',
157  '.mov' => 'video/quicktime',
158  '.movie' => 'video/x-sgi-movie',
159  '.mp2' => 'audio/mpeg',
160  '.mp3' => 'audio/mpeg',
161  '.mpa' => 'video/mpeg',
162  '.mpe' => 'video/mpeg',
163  '.mpeg' => 'video/mpeg',
164  '.mpg' => 'video/mpeg',
165  '.mp4' => 'video/mp4',
166  '.mv4' => 'video/mp4',
167  '.ms' => 'application/x-troff-ms',
168  '.nc' => 'application/x-netcdf',
169  '.nws' => 'message/rfc822',
170  '.o' => 'application/octet-stream',
171  '.ogg' => 'application/ogg',
172  '.oga' => 'audio/ogg',
173  '.ogv' => 'video/ogg',
174  '.obj' => 'application/octet-stream',
175  '.oda' => 'application/oda',
176  '.p12' => 'application/x-pkcs12',
177  '.p7c' => 'application/pkcs7-mime',
178  '.pbm' => 'image/x-portable-bitmap',
179  '.pdf' => 'application/pdf',
180  '.pfx' => 'application/x-pkcs12',
181  '.pgm' => 'image/x-portable-graymap',
182  '.php' => 'application/x-httpd-php',
183  '.phtml' => 'application/x-httpd-php',
184  '.pl' => 'text/plain',
185  '.png' => 'image/png',
186  '.pnm' => 'image/x-portable-anymap',
187  '.pot' => 'application/vnd.ms-powerpoint',
188  '.potx' => 'application/vnd.openxmlformats-officedocument.presentationml.template',
189  '.ppa' => 'application/vnd.ms-powerpoint',
190  '.ppm' => 'image/x-portable-pixmap',
191  '.pps' => 'application/vnd.ms-powerpoint',
192  '.ppsx' => 'application/vnd.openxmlformats-officedocument.presentationml.slideshow',
193  '.ppt' => 'application/vnd.ms-powerpoint',
194  '.pptx' => 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
195  '.ps' => 'application/postscript',
196  '.psd' => 'image/psd',
197  '.pwz' => 'application/vnd.ms-powerpoint',
198  '.py' => 'text/x-python',
199  '.pyc' => 'application/x-python-code',
200  '.pyo' => 'application/x-python-code',
201  '.qt' => 'video/quicktime',
202  '.ra' => 'audio/x-pn-realaudio',
203  '.ram' => 'application/x-pn-realaudio',
204  '.ras' => 'image/x-cmu-raster',
205  '.rdf' => 'application/xml',
206  '.rgb' => 'image/x-rgb',
207  '.roff' => 'application/x-troff',
208  '.rpm' => 'audio/x-pn-realaudio-plugin',
209  '.rtf' => 'application/rtf',
210  '.rtx' => 'text/richtext',
211  '.sgm' => 'text/x-sgml',
212  '.sgml' => 'text/x-sgml',
213  '.sh' => 'application/x-sh',
214  '.shar' => 'application/x-shar',
215  '.sit' => 'application/x-stuffit',
216  '.sldx' => 'application/vnd.openxmlformats-officedocument.presentationml.slide',
217  '.snd' => 'audio/basic',
218  '.so' => 'application/octet-stream',
219  '.spc' => 'text/x-speech',
220  '.src' => 'application/x-wais-source',
221  '.sv4cpio'=> 'application/x-sv4cpio',
222  '.sv4crc' => 'application/x-sv4crc',
223  '.svg' => 'image/svg+xml',
224  '.swf' => 'application/x-shockwave-flash',
225  '.t' => 'application/x-troff',
226  '.tar' => 'application/x-tar',
227  '.talk' => 'text/x-speech',
228  '.tbk' => 'application/toolbook',
229  '.tcl' => 'application/x-tcl',
230  '.tex' => 'application/x-tex',
231  '.texi' => 'application/x-texinfo',
232  '.texinfo'=> 'application/x-texinfo',
233  '.tif' => 'image/tiff',
234  '.tiff' => 'image/tiff',
235  '.tr' => 'application/x-troff',
236  '.tsv' => 'text/tab-separated-values',
237  '.tsp' => 'application/dsptype',
238  '.txt' => 'text/plain',
239  '.ustar' => 'application',
240  '.vcf' => 'text/x-vcard',
241  '.vimeo' => 'video/vimeo',
242  '.vox' => 'audio/voxware',
243  '.wav' => 'audio/x-wav',
244  '.wax' => 'audio/x-ms-wax',
245  '.wiz' => 'application/msword',
246  '.webm' => 'video/webm',
247  '.wm' => 'video/x-ms-wm',
248  '.wma' => 'audio/x-ms-wma',
249  '.wmd' => 'video/x-ms-wmd',
250  '.wml' => 'text/vnd.wap.wml',
251  '.wmlc' => 'application/vnd.wap.wmlc',
252  '.wmls' => 'text/vnd.wap.wmlscript',
253  '.wmlsc' => 'application/vnd.wap.wmlscriptc',
254  '.wmv' => 'video/x-ms-wmv',
255  '.wmx' => 'video/x-ms-wmx',
256  '.wmz' => 'video/x-ms-wmz',
257  '.wvx' => 'video/x-ms-wvx',
258  '.wrl' => 'x-world/x-vrml',
259  '.xbm' => 'image/x-xbitmap',
260  '.xla' => 'application/msexcel',
261  '.xlam' => 'application/vnd.ms-excel.addin.macroEnabled.12',
262  '.xlb' => 'application/vnd.ms-excel',
263  '.xls' => 'application/msexcel',
264  '.xlsb' => 'application/vnd.ms-excel.sheet.binary.macroEnabled.12',
265  '.xml' => 'text/xml',
266  '.xpm' => 'image/x-xpixmap',
267  '.xsl' => 'application/xml',
268  '.xlsx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
269  '.xltx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.template',
270  '.xwd' => 'image/x-xwindowdump',
271  '.youtube' => 'video/youtube',
272  '.zip' => 'application/zip');
273 
274  return $types_map;
275  }
+ Here is the caller graph for this function:

◆ getMimeType()

static ilMimeTypeUtil::getMimeType (   $a_file = "",
  $a_filename = "",
  $a_mime = "" 
)
static

Get Mime type.

Parameters
stringfull path of file (incl. filename)
stringfile name (must be provided if no full path is given)
stringmime type that will be used initially. Provide any mime type headers

Definition at line 22 of file class.ilMimeTypeUtil.php.

References $ilLog, $path, and getExt2MimeMap().

Referenced by ilObjectDAV\createFile(), ilWebAccessChecker\getMimeType(), ilObjMediaObject\getMimeType(), ilObjFile\guessFileType(), ilObjFileGUI\handleFileUpload(), ilDataCollectionDatatype\parseValue(), ilObjFileGUI\save(), ilObjFileGUI\update(), and ilFileSystemGUI\uploadFile().

23  {
24  global $ilLog;
25 
26  $mime = "";
27 
28  // if we have an http reference , we check for youtube
29  if (in_array(substr($a_file, 0, 7), array("http://", "https:/")))
30  {
31  if (is_int(strpos($a_file, "youtube.")))
32  {
33  return "video/youtube";
34  }
35  if (is_int(strpos($a_file, "vimeo.")))
36  {
37  return "video/vimeo";
38  }
39  }
40 
41  // determine extension
42  $ext = "";
43  if ($a_filename != "") // first check the file name provided
44  {
45  $path = pathinfo($a_filename);
46  $ext = ".".strtolower($path["extension"]);
47  }
48  else if ($a_file != "") // check if (full path) file has been provided
49  {
50  $path = pathinfo($a_file);
51  $ext = ".".strtolower($path["extension"]);
52  }
53 
54  $types_map = ilMimeTypeUtil::getExt2MimeMap();
55  if ($types_map[$ext] != "") // if we find something in our map, use it
56  {
57  $mime = $types_map[$ext];
58  }
59 
60  if ($mime == "" && extension_loaded('Fileinfo') &&
61  is_file($a_file))
62  {
63  $finfo = finfo_open(FILEINFO_MIME);
64  $mime = finfo_file($finfo, $a_file);
65  finfo_close($finfo);
66  if ($pos = strpos($mime, ' '))
67  {
68  $mime = substr($mime, 0, $pos);
69  }
70  // remove trailing ";"
71  if (substr($mime, strlen($mime) - 1, 1) == ";")
72  {
73  $mime = substr($mime, 0, strlen($mime) - 1);
74  }
75  }
76 
77  if ($mime == "")
78  {
79  $mime = "application/octet-stream";
80  }
81 
82  return $mime;
83  }
$path
Definition: index.php:22
static getExt2MimeMap()
get file extension to mime type map
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

The documentation for this class was generated from the following file: