]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - extlib/MIME/Type/Extension.php
1987e2a10e4678ae50d1245b70e18ca2cf4adf8b
[quix0rs-gnu-social.git] / extlib / MIME / Type / Extension.php
1 <?php
2 /* vim: set expandtab tabstop=4 shiftwidth=4: */
3 // +----------------------------------------------------------------------+
4 // | PHP versions 4 and 5                                                 |
5 // +----------------------------------------------------------------------+
6 // | Copyright (c) 1997-2009 The PHP Group                                |
7 // +----------------------------------------------------------------------+
8 // | This source file is subject to version 3.0 of the PHP license,       |
9 // | that is bundled with this package in the file LICENSE, and is        |
10 // | available at through the world-wide-web at                           |
11 // | http://www.php.net/license/3_0.txt.                                  |
12 // | If you did not receive a copy of the PHP license and are unable to   |
13 // | obtain it through the world-wide-web, please send a note to          |
14 // | license@php.net so we can mail you a copy immediately.               |
15 // +----------------------------------------------------------------------+
16 // | Authors: Christian Schmidt <schmidt@php.net>                         |
17 // +----------------------------------------------------------------------+
18 //
19 // $Id: Extension.php,v 1.1 2009/01/16 11:49:45 cweiske Exp $
20
21 require_once 'PEAR.php';
22
23 /**
24  * Class for mapping file extensions to MIME types.
25  *
26  * @category MIME
27  * @package  MIME_Type
28  * @author   Christian Schmidt <schmidt@php.net>
29  * @license  PHP License 3.0
30  * @version  1.2.0
31  * @link     http://pear.php.net/package/MIME_Type
32  */
33 class MIME_Type_Extension
34 {
35     /**
36      * Mapping between file extension and MIME type.
37      *
38      * @internal The array is sorted alphabetically by value and with primary
39      *  extension first. Be careful about not adding duplicate keys - PHP
40      *  silently ignores duplicates. The following command can be used for
41      *  checking for duplicates:
42      *    grep "=> '" Extension.php | cut -d\' -f2 | sort | uniq -d
43      *  application/octet-stream is generally used as fallback when no other
44      *  MIME-type can be found, but the array does not contain a lot of such
45      *  unknown extension. One entry exists, though, to allow detection of
46      *  file extension for this MIME-type.
47      *
48      * @var array
49      */
50     var $extensionToType = array (
51         'ez'        => 'application/andrew-inset',
52         'atom'      => 'application/atom+xml',
53         'jar'       => 'application/java-archive',
54         'hqx'       => 'application/mac-binhex40',
55         'cpt'       => 'application/mac-compactpro',
56         'mathml'    => 'application/mathml+xml',
57         'doc'       => 'application/msword',
58         'dat'       => 'application/octet-stream',
59         'oda'       => 'application/oda',
60         'ogg'       => 'application/ogg',
61         'pdf'       => 'application/pdf',
62         'ai'        => 'application/postscript',
63         'eps'       => 'application/postscript',
64         'ps'        => 'application/postscript',
65         'rdf'       => 'application/rdf+xml',
66         'rss'       => 'application/rss+xml',
67         'smi'       => 'application/smil',
68         'smil'      => 'application/smil',
69         'gram'      => 'application/srgs',
70         'grxml'     => 'application/srgs+xml',
71         'kml'       => 'application/vnd.google-earth.kml+xml',
72         'kmz'       => 'application/vnd.google-earth.kmz',
73         'mif'       => 'application/vnd.mif',
74         'xul'       => 'application/vnd.mozilla.xul+xml',
75         'xls'       => 'application/vnd.ms-excel',
76         'xlb'       => 'application/vnd.ms-excel',
77         'xlt'       => 'application/vnd.ms-excel',
78         'xlam'      => 'application/vnd.ms-excel.addin.macroEnabled.12',
79         'xlsb'      => 'application/vnd.ms-excel.sheet.binary.macroEnabled.12',
80         'xlsm'      => 'application/vnd.ms-excel.sheet.macroEnabled.12',
81         'xltm'      => 'application/vnd.ms-excel.template.macroEnabled.12',
82         'docm'      => 'application/vnd.ms-word.document.macroEnabled.12',
83         'dotm'      => 'application/vnd.ms-word.template.macroEnabled.12',
84         'ppam'      => 'application/vnd.ms-powerpoint.addin.macroEnabled.12',
85         'pptm'      => 'application/vnd.ms-powerpoint.presentation.macroEnabled.12',
86         'ppsm'      => 'application/vnd.ms-powerpoint.slideshow.macroEnabled.12',
87         'potm'      => 'application/vnd.ms-powerpoint.template.macroEnabled.12',
88         'ppt'       => 'application/vnd.ms-powerpoint',
89         'pps'       => 'application/vnd.ms-powerpoint',
90         'odc'       => 'application/vnd.oasis.opendocument.chart',
91         'odb'       => 'application/vnd.oasis.opendocument.database',
92         'odf'       => 'application/vnd.oasis.opendocument.formula',
93         'odg'       => 'application/vnd.oasis.opendocument.graphics',
94         'otg'       => 'application/vnd.oasis.opendocument.graphics-template',
95         'odi'       => 'application/vnd.oasis.opendocument.image',
96         'odp'       => 'application/vnd.oasis.opendocument.presentation',
97         'otp'       => 'application/vnd.oasis.opendocument.presentation-template',
98         'ods'       => 'application/vnd.oasis.opendocument.spreadsheet',
99         'ots'       => 'application/vnd.oasis.opendocument.spreadsheet-template',
100         'odt'       => 'application/vnd.oasis.opendocument.text',
101         'odm'       => 'application/vnd.oasis.opendocument.text-master',
102         'ott'       => 'application/vnd.oasis.opendocument.text-template',
103         'oth'       => 'application/vnd.oasis.opendocument.text-web',
104         'potx'      => 'application/vnd.openxmlformats-officedocument.presentationml.template',
105         'ppsx'      => 'application/vnd.openxmlformats-officedocument.presentationml.slideshow',
106         'pptx'      => 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
107         'xlsx'      => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
108         'xltx'      => 'application/vnd.openxmlformats-officedocument.spreadsheetml.template',
109         'docx'      => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
110         'dotx'      => 'application/vnd.openxmlformats-officedocument.wordprocessingml.template',
111         'vsd'       => 'application/vnd.visio',
112         'wbxml'     => 'application/vnd.wap.wbxml',
113         'wmlc'      => 'application/vnd.wap.wmlc',
114         'wmlsc'     => 'application/vnd.wap.wmlscriptc',
115         'vxml'      => 'application/voicexml+xml',
116         'bcpio'     => 'application/x-bcpio',
117         'vcd'       => 'application/x-cdlink',
118         'pgn'       => 'application/x-chess-pgn',
119         'cpio'      => 'application/x-cpio',
120         'csh'       => 'application/x-csh',
121         'dcr'       => 'application/x-director',
122         'dir'       => 'application/x-director',
123         'dxr'       => 'application/x-director',
124         'dvi'       => 'application/x-dvi',
125         'spl'       => 'application/x-futuresplash',
126         'tgz'       => 'application/x-gtar',
127         'gtar'      => 'application/x-gtar',
128         'hdf'       => 'application/x-hdf',
129         'js'        => 'application/x-javascript',
130         'skp'       => 'application/x-koan',
131         'skd'       => 'application/x-koan',
132         'skt'       => 'application/x-koan',
133         'skm'       => 'application/x-koan',
134         'latex'     => 'application/x-latex',
135         'nc'        => 'application/x-netcdf',
136         'cdf'       => 'application/x-netcdf',
137         'sh'        => 'application/x-sh',
138         'shar'      => 'application/x-shar',
139         'swf'       => 'application/x-shockwave-flash',
140         'sit'       => 'application/x-stuffit',
141         'sv4cpio'   => 'application/x-sv4cpio',
142         'sv4crc'    => 'application/x-sv4crc',
143         'tar'       => 'application/x-tar',
144         'tcl'       => 'application/x-tcl',
145         'tex'       => 'application/x-tex',
146         'texinfo'   => 'application/x-texinfo',
147         'texi'      => 'application/x-texinfo',
148         't'         => 'application/x-troff',
149         'tr'        => 'application/x-troff',
150         'roff'      => 'application/x-troff',
151         'man'       => 'application/x-troff-man',
152         'me'        => 'application/x-troff-me',
153         'ms'        => 'application/x-troff-ms',
154         'ustar'     => 'application/x-ustar',
155         'src'       => 'application/x-wais-source',
156         'xhtml'     => 'application/xhtml+xml',
157         'xht'       => 'application/xhtml+xml',
158         'xslt'      => 'application/xslt+xml',
159         'xml'       => 'application/xml',
160         'xsl'       => 'application/xml',
161         'dtd'       => 'application/xml-dtd',
162         'zip'       => 'application/zip',
163         'au'        => 'audio/basic',
164         'snd'       => 'audio/basic',
165         'mid'       => 'audio/midi',
166         'midi'      => 'audio/midi',
167         'kar'       => 'audio/midi',
168         'mpga'      => 'audio/mpeg',
169         'mp2'       => 'audio/mpeg',
170         'mp3'       => 'audio/mpeg',
171         'aif'       => 'audio/x-aiff',
172         'aiff'      => 'audio/x-aiff',
173         'aifc'      => 'audio/x-aiff',
174         'm3u'       => 'audio/x-mpegurl',
175         'wma'       => 'audio/x-ms-wma',
176         'wax'       => 'audio/x-ms-wax',
177         'ram'       => 'audio/x-pn-realaudio',
178         'ra'        => 'audio/x-pn-realaudio',
179         'rm'        => 'application/vnd.rn-realmedia',
180         'wav'       => 'audio/x-wav',
181         'pdb'       => 'chemical/x-pdb',
182         'xyz'       => 'chemical/x-xyz',
183         'bmp'       => 'image/bmp',
184         'cgm'       => 'image/cgm',
185         'gif'       => 'image/gif',
186         'ief'       => 'image/ief',
187         'jpeg'      => 'image/jpeg',
188         'jpg'       => 'image/jpeg',
189         'jpe'       => 'image/jpeg',
190         'png'       => 'image/png',
191         'svg'       => 'image/svg+xml',
192         'tiff'      => 'image/tiff',
193         'tif'       => 'image/tiff',
194         'djvu'      => 'image/vnd.djvu',
195         'djv'       => 'image/vnd.djvu',
196         'wbmp'      => 'image/vnd.wap.wbmp',
197         'ras'       => 'image/x-cmu-raster',
198         'ico'       => 'image/x-icon',
199         'pnm'       => 'image/x-portable-anymap',
200         'pbm'       => 'image/x-portable-bitmap',
201         'pgm'       => 'image/x-portable-graymap',
202         'ppm'       => 'image/x-portable-pixmap',
203         'rgb'       => 'image/x-rgb',
204         'xbm'       => 'image/x-xbitmap',
205         'psd'       => 'image/x-photoshop',
206         'xpm'       => 'image/x-xpixmap',
207         'xwd'       => 'image/x-xwindowdump',
208         'eml'       => 'message/rfc822',
209         'igs'       => 'model/iges',
210         'iges'      => 'model/iges',
211         'msh'       => 'model/mesh',
212         'mesh'      => 'model/mesh',
213         'silo'      => 'model/mesh',
214         'wrl'       => 'model/vrml',
215         'vrml'      => 'model/vrml',
216         'ics'       => 'text/calendar',
217         'ifb'       => 'text/calendar',
218         'css'       => 'text/css',
219         'csv'       => 'text/csv',
220         'html'      => 'text/html',
221         'htm'       => 'text/html',
222         'txt'       => 'text/plain',
223         'asc'       => 'text/plain',
224         'rtx'       => 'text/richtext',
225         'rtf'       => 'text/rtf',
226         'sgml'      => 'text/sgml',
227         'sgm'       => 'text/sgml',
228         'tsv'       => 'text/tab-separated-values',
229         'wml'       => 'text/vnd.wap.wml',
230         'wmls'      => 'text/vnd.wap.wmlscript',
231         'etx'       => 'text/x-setext',
232         'mpeg'      => 'video/mpeg',
233         'mpg'       => 'video/mpeg',
234         'mpe'       => 'video/mpeg',
235         'qt'        => 'video/quicktime',
236         'mov'       => 'video/quicktime',
237         'mxu'       => 'video/vnd.mpegurl',
238         'm4u'       => 'video/vnd.mpegurl',
239         'flv'       => 'video/x-flv',
240         'asf'       => 'video/x-ms-asf',
241         'asx'       => 'video/x-ms-asf',
242         'wmv'       => 'video/x-ms-wmv',
243         'wm'        => 'video/x-ms-wm',
244         'wmx'       => 'video/x-ms-wmx',
245         'avi'       => 'video/x-msvideo',
246         'ogv'       => 'video/ogg',
247         'movie'     => 'video/x-sgi-movie',
248         'ice'       => 'x-conference/x-cooltalk',
249     );
250
251
252
253     /**
254      * Autodetect a file's MIME-type.
255      *
256      * @param string $file Path to the file to get the type of
257      *
258      * @return string $file's MIME-type on success, PEAR_Error otherwise
259      */
260     function getMIMEType($file)
261     {
262         $extension = substr(strrchr($file, '.'), 1);
263         if ($extension === false) {
264             return PEAR::raiseError("File has no extension.");
265         }
266
267         if (!isset($this->extensionToType[$extension])) {
268             return PEAR::raiseError("Sorry, couldn't determine file type.");
269         }
270
271         return $this->extensionToType[$extension];
272     }
273
274
275
276     /**
277      * Return default MIME-type for the specified extension.
278      *
279      * @param string $type MIME-type
280      *
281      * @return string A file extension without leading period.
282      */
283     function getExtension($type)
284     {
285         require_once 'MIME/Type.php';
286         // Strip parameters and comments.
287         $type = MIME_Type::getMedia($type) . '/' . MIME_Type::getSubType($type);
288
289         $extension = array_search($type, $this->extensionToType);
290         if ($extension === false) {
291             return PEAR::raiseError("Sorry, couldn't determine extension.");
292         }
293         return $extension;
294     }
295
296 }
297
298 ?>