| 3 |
liveuser |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
namespace GuzzleHttp\Psr7;
|
|
|
4 |
|
|
|
5 |
final class MimeType
|
|
|
6 |
{
|
|
|
7 |
/**
|
|
|
8 |
* Determines the mimetype of a file by looking at its extension.
|
|
|
9 |
*
|
|
|
10 |
* @param string $filename
|
|
|
11 |
*
|
|
|
12 |
* @return string|null
|
|
|
13 |
*/
|
|
|
14 |
public static function fromFilename($filename)
|
|
|
15 |
{
|
|
|
16 |
return self::fromExtension(pathinfo($filename, PATHINFO_EXTENSION));
|
|
|
17 |
}
|
|
|
18 |
|
|
|
19 |
/**
|
|
|
20 |
* Maps a file extensions to a mimetype.
|
|
|
21 |
*
|
|
|
22 |
* @param string $extension string The file extension.
|
|
|
23 |
*
|
|
|
24 |
* @return string|null
|
|
|
25 |
*
|
|
|
26 |
* @link http://svn.apache.org/repos/asf/httpd/httpd/branches/1.3.x/conf/mime.types
|
|
|
27 |
*/
|
|
|
28 |
public static function fromExtension($extension)
|
|
|
29 |
{
|
|
|
30 |
static $mimetypes = [
|
|
|
31 |
'3gp' => 'video/3gpp',
|
|
|
32 |
'7z' => 'application/x-7z-compressed',
|
|
|
33 |
'aac' => 'audio/x-aac',
|
|
|
34 |
'ai' => 'application/postscript',
|
|
|
35 |
'aif' => 'audio/x-aiff',
|
|
|
36 |
'asc' => 'text/plain',
|
|
|
37 |
'asf' => 'video/x-ms-asf',
|
|
|
38 |
'atom' => 'application/atom+xml',
|
|
|
39 |
'avi' => 'video/x-msvideo',
|
|
|
40 |
'bmp' => 'image/bmp',
|
|
|
41 |
'bz2' => 'application/x-bzip2',
|
|
|
42 |
'cer' => 'application/pkix-cert',
|
|
|
43 |
'crl' => 'application/pkix-crl',
|
|
|
44 |
'crt' => 'application/x-x509-ca-cert',
|
|
|
45 |
'css' => 'text/css',
|
|
|
46 |
'csv' => 'text/csv',
|
|
|
47 |
'cu' => 'application/cu-seeme',
|
|
|
48 |
'deb' => 'application/x-debian-package',
|
|
|
49 |
'doc' => 'application/msword',
|
|
|
50 |
'docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
|
|
|
51 |
'dvi' => 'application/x-dvi',
|
|
|
52 |
'eot' => 'application/vnd.ms-fontobject',
|
|
|
53 |
'eps' => 'application/postscript',
|
|
|
54 |
'epub' => 'application/epub+zip',
|
|
|
55 |
'etx' => 'text/x-setext',
|
|
|
56 |
'flac' => 'audio/flac',
|
|
|
57 |
'flv' => 'video/x-flv',
|
|
|
58 |
'gif' => 'image/gif',
|
|
|
59 |
'gz' => 'application/gzip',
|
|
|
60 |
'htm' => 'text/html',
|
|
|
61 |
'html' => 'text/html',
|
|
|
62 |
'ico' => 'image/x-icon',
|
|
|
63 |
'ics' => 'text/calendar',
|
|
|
64 |
'ini' => 'text/plain',
|
|
|
65 |
'iso' => 'application/x-iso9660-image',
|
|
|
66 |
'jar' => 'application/java-archive',
|
|
|
67 |
'jpe' => 'image/jpeg',
|
|
|
68 |
'jpeg' => 'image/jpeg',
|
|
|
69 |
'jpg' => 'image/jpeg',
|
|
|
70 |
'js' => 'text/javascript',
|
|
|
71 |
'json' => 'application/json',
|
|
|
72 |
'latex' => 'application/x-latex',
|
|
|
73 |
'log' => 'text/plain',
|
|
|
74 |
'm4a' => 'audio/mp4',
|
|
|
75 |
'm4v' => 'video/mp4',
|
|
|
76 |
'mid' => 'audio/midi',
|
|
|
77 |
'midi' => 'audio/midi',
|
|
|
78 |
'mov' => 'video/quicktime',
|
|
|
79 |
'mkv' => 'video/x-matroska',
|
|
|
80 |
'mp3' => 'audio/mpeg',
|
|
|
81 |
'mp4' => 'video/mp4',
|
|
|
82 |
'mp4a' => 'audio/mp4',
|
|
|
83 |
'mp4v' => 'video/mp4',
|
|
|
84 |
'mpe' => 'video/mpeg',
|
|
|
85 |
'mpeg' => 'video/mpeg',
|
|
|
86 |
'mpg' => 'video/mpeg',
|
|
|
87 |
'mpg4' => 'video/mp4',
|
|
|
88 |
'oga' => 'audio/ogg',
|
|
|
89 |
'ogg' => 'audio/ogg',
|
|
|
90 |
'ogv' => 'video/ogg',
|
|
|
91 |
'ogx' => 'application/ogg',
|
|
|
92 |
'pbm' => 'image/x-portable-bitmap',
|
|
|
93 |
'pdf' => 'application/pdf',
|
|
|
94 |
'pgm' => 'image/x-portable-graymap',
|
|
|
95 |
'png' => 'image/png',
|
|
|
96 |
'pnm' => 'image/x-portable-anymap',
|
|
|
97 |
'ppm' => 'image/x-portable-pixmap',
|
|
|
98 |
'ppt' => 'application/vnd.ms-powerpoint',
|
|
|
99 |
'pptx' => 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
|
|
|
100 |
'ps' => 'application/postscript',
|
|
|
101 |
'qt' => 'video/quicktime',
|
|
|
102 |
'rar' => 'application/x-rar-compressed',
|
|
|
103 |
'ras' => 'image/x-cmu-raster',
|
|
|
104 |
'rss' => 'application/rss+xml',
|
|
|
105 |
'rtf' => 'application/rtf',
|
|
|
106 |
'sgm' => 'text/sgml',
|
|
|
107 |
'sgml' => 'text/sgml',
|
|
|
108 |
'svg' => 'image/svg+xml',
|
|
|
109 |
'swf' => 'application/x-shockwave-flash',
|
|
|
110 |
'tar' => 'application/x-tar',
|
|
|
111 |
'tif' => 'image/tiff',
|
|
|
112 |
'tiff' => 'image/tiff',
|
|
|
113 |
'torrent' => 'application/x-bittorrent',
|
|
|
114 |
'ttf' => 'application/x-font-ttf',
|
|
|
115 |
'txt' => 'text/plain',
|
|
|
116 |
'wav' => 'audio/x-wav',
|
|
|
117 |
'webm' => 'video/webm',
|
|
|
118 |
'webp' => 'image/webp',
|
|
|
119 |
'wma' => 'audio/x-ms-wma',
|
|
|
120 |
'wmv' => 'video/x-ms-wmv',
|
|
|
121 |
'woff' => 'application/x-font-woff',
|
|
|
122 |
'wsdl' => 'application/wsdl+xml',
|
|
|
123 |
'xbm' => 'image/x-xbitmap',
|
|
|
124 |
'xls' => 'application/vnd.ms-excel',
|
|
|
125 |
'xlsx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
|
|
126 |
'xml' => 'application/xml',
|
|
|
127 |
'xpm' => 'image/x-xpixmap',
|
|
|
128 |
'xwd' => 'image/x-xwindowdump',
|
|
|
129 |
'yaml' => 'text/yaml',
|
|
|
130 |
'yml' => 'text/yaml',
|
|
|
131 |
'zip' => 'application/zip',
|
|
|
132 |
];
|
|
|
133 |
|
|
|
134 |
$extension = strtolower($extension);
|
|
|
135 |
|
|
|
136 |
return isset($mimetypes[$extension])
|
|
|
137 |
? $mimetypes[$extension]
|
|
|
138 |
: null;
|
|
|
139 |
}
|
|
|
140 |
}
|