1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
mimetype.php
См. документацию.
1<?php
2namespace Bitrix\Main\Web;
3
4use Bitrix\Main\IO;
5
6final class MimeType
7{
8 protected static $mimes = [
9 'hqx' => 'application/mac-binhex40',
10 'cpt' => 'application/mac-compactpro',
11 'csv' => 'text/x-comma-separated-values',
12 'bin' => 'application/octet-stream',
13 'dms' => 'application/octet-stream',
14 'lha' => 'application/octet-stream',
15 'lzh' => 'application/octet-stream',
16 'exe' => 'application/octet-stream',
17 'class' => 'application/octet-stream',
18 'psd' => 'application/x-photoshop',
19 'so' => 'application/octet-stream',
20 'sea' => 'application/octet-stream',
21 'dll' => 'application/octet-stream',
22 'oda' => 'application/oda',
23 'pdf' => 'application/pdf',
24 'ai' => 'application/pdf',
25 'eps' => 'application/postscript',
26 'ps' => 'application/postscript',
27 'smi' => 'application/smil',
28 'smil' => 'application/smil',
29 'mif' => 'application/vnd.mif',
30 'xls' => 'application/vnd.ms-excel',
31 'ppt' => 'application/powerpoint',
32 'pptx' => 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
33 'wbxml' => 'application/wbxml',
34 'wmlc' => 'application/wmlc',
35 'dcr' => 'application/x-director',
36 'dir' => 'application/x-director',
37 'dxr' => 'application/x-director',
38 'dvi' => 'application/x-dvi',
39 'gtar' => 'application/x-gtar',
40 'gz' => 'application/x-gzip',
41 'gzip' => 'application/x-gzip',
42 'php' => 'application/x-httpd-php',
43 'php4' => 'application/x-httpd-php',
44 'php3' => 'application/x-httpd-php',
45 'phtml' => 'application/x-httpd-php',
46 'phps' => 'application/x-httpd-php-source',
47 'js' => 'application/javascript',
48 'swf' => 'application/x-shockwave-flash',
49 'sit' => 'application/x-stuffit',
50 'tar' => 'application/x-tar',
51 'tgz' => 'application/x-tar',
52 'z' => 'application/x-compress',
53 'xhtml' => 'application/xhtml+xml',
54 'xht' => 'application/xhtml+xml',
55 'zip' => 'application/x-zip',
56 'rar' => 'application/x-rar',
57 'mid' => 'audio/midi',
58 'midi' => 'audio/midi',
59 'mpga' => 'audio/mpeg',
60 'mp2' => 'audio/mpeg',
61 'mp3' => 'audio/mpeg',
62 'aif' => 'audio/x-aiff',
63 'aiff' => 'audio/x-aiff',
64 'aifc' => 'audio/x-aiff',
65 'ram' => 'audio/x-pn-realaudio',
66 'rm' => 'audio/x-pn-realaudio',
67 'rpm' => 'audio/x-pn-realaudio-plugin',
68 'ra' => 'audio/x-realaudio',
69 'rv' => 'video/vnd.rn-realvideo',
70 'wav' => 'audio/x-wav',
71 'jpg' => 'image/jpeg',
72 'jpeg' => 'image/jpeg',
73 'jpe' => 'image/jpeg',
74 'png' => 'image/png',
75 'webp' => 'image/webp',
76 'gif' => 'image/gif',
77 'bmp' => 'image/bmp',
78 'tiff' => 'image/tiff',
79 'tif' => 'image/tiff',
80 'svg' => 'image/svg+xml',
81 'css' => 'text/css',
82 'html' => 'text/html',
83 'htm' => 'text/html',
84 'shtml' => 'text/html',
85 'txt' => 'text/plain',
86 'text' => 'text/plain',
87 'log' => 'text/plain',
88 'rtx' => 'text/richtext',
89 'rtf' => 'text/rtf',
90 'xml' => 'application/xml',
91 'xsl' => 'application/xml',
92 'mpeg' => 'video/mpeg',
93 'mpg' => 'video/mpeg',
94 'mpe' => 'video/mpeg',
95 'qt' => 'video/quicktime',
96 'mov' => 'video/quicktime',
97 'avi' => 'video/x-msvideo',
98 'movie' => 'video/x-sgi-movie',
99 'doc' => 'application/msword',
100 'docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
101 'dot' => 'application/msword',
102 'dotx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
103 'xlsx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
104 'word' => 'application/msword',
105 'xl' => 'application/excel',
106 'eml' => 'message/rfc822',
107 'json' => 'application/json',
108 'pem' => 'application/x-x509-user-cert',
109 'p10' => 'application/x-pkcs10',
110 'p12' => 'application/x-pkcs12',
111 'p7a' => 'application/x-pkcs7-signature',
112 'p7c' => 'application/pkcs7-mime',
113 'p7m' => 'application/pkcs7-mime',
114 'p7r' => 'application/x-pkcs7-certreqresp',
115 'p7s' => 'application/pkcs7-signature',
116 'crt' => 'application/x-x509-ca-cert',
117 'crl' => 'application/pkix-crl',
118 'der' => 'application/x-x509-ca-cert',
119 'kdb' => 'application/octet-stream',
120 'pgp' => 'application/pgp',
121 'gpg' => 'application/gpg-keys',
122 'sst' => 'application/octet-stream',
123 'csr' => 'application/octet-stream',
124 'rsa' => 'application/x-pkcs7',
125 'cer' => 'application/pkix-cert',
126 '3g2' => 'video/3gpp2',
127 '3gp' => 'video/3gp',
128 'mp4' => 'video/mp4',
129 'm4a' => 'audio/x-m4a',
130 'f4v' => 'video/mp4',
131 'webm' => 'video/webm',
132 'aac' => 'audio/x-acc',
133 'm4u' => 'application/vnd.mpegurl',
134 'm3u' => 'text/plain',
135 'xspf' => 'application/xspf+xml',
136 'vlc' => 'application/videolan',
137 'wmv' => 'video/x-ms-wmv',
138 'au' => 'audio/x-au',
139 'ac3' => 'audio/ac3',
140 'flac' => 'audio/x-flac',
141 'ogg' => 'audio/ogg',
142 'kmz' => 'application/vnd.google-earth.kmz',
143 'kml' => 'application/vnd.google-earth.kml+xml',
144 'ics' => 'text/calendar',
145 'zsh' => 'text/x-scriptzsh',
146 '7zip' => 'application/x-7z-compressed',
147 'cdr' => 'application/cdr',
148 'wma' => 'audio/x-ms-wma',
149 'jar' => 'application/java-archive',
150 'sketch' => 'application/octet-stream',
151 'vsd' => 'application/vnd.ms-visio',
152 'vsdx' => 'application/vnd.ms-visio.drawing',
153 'docm' => 'application/vnd.ms-word.document.macroEnabled.12',
154 'dotm' => 'application/vnd.ms-word.template.macroEnabled.12',
155 'potm' => 'application/vnd.ms-powerpoint.template.macroEnabled.12',
156 'potx' => 'application/vnd.openxmlformats-officedocument.presentationml.template',
157 'ppam' => 'application/vnd.ms-powerpoint.addin.macroEnabled.12',
158 'ppsm' => 'application/vnd.ms-powerpoint.slideshow.macroEnabled.12',
159 'ppsx' => 'application/vnd.openxmlformats-officedocument.presentationml.slideshow',
160 'pptm' => 'application/vnd.ms-powerpoint.presentation.macroEnabled.12',
161 'xlam' => 'application/vnd.ms-excel.addin.macroEnabled.12',
162 'xlsb' => 'application/vnd.ms-excel.sheet.binary.macroEnabled.12',
163 'xlsm' => 'application/vnd.ms-excel.sheet.macroEnabled.12',
164 'xltm' => 'application/vnd.ms-excel.template.macroEnabled.12',
165 'xltx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.template',
166 'fb2' => 'application/xml',
167 'djvu' => 'image/vnd.djvu',
168 'epub' => 'application/epub+zip',
169 'msg' => 'message/rfc822',
170 'ott' => 'application/vnd.oasis.opendocument.text-template',
171 'otp' => 'application/vnd.oasis.opendocument.presentation-template',
172 'ots' => 'application/vnd.oasis.opendocument.spreadsheet-template',
173 'odt' => 'application/vnd.oasis.opendocument.text',
174 'odp' => 'application/vnd.oasis.opendocument.presentation',
175 'ods' => 'application/vnd.oasis.opendocument.spreadsheet',
176 'xodt' => 'application/vnd.collabio.xodocuments.document',
177 '7z' => 'application/x-7z-compressed',
178 'bz2' => 'application/x-bzip2',
179 'mp4v' => 'video/mp4',
180 'mpg4' => 'video/mp4',
181 'ogv' => 'video/ogg',
182 'flv' => 'video/x-flv',
183 'mkv' => 'video/x-matroska',
184 'm4v' => 'video/x-m4v',
185 'h264' => 'video/h264',
186 'sql' => 'text/plain',
187 'pl' => 'text/plain',
188 'sh' => 'text/plain',
189 'ttf' => 'application/x-font-ttf',
190 'otf' => 'application/vnd.ms-opentype',
191 'eot' => 'application/vnd.ms-fontobject',
192 'woff' => 'application/font-woff',
193 'pfa' => 'application/x-font-type1',
194 'xla' => "application/vnd.ms-excel",
195 'xlb' => 'application/vnd.ms-excel',
196 'xlc' => 'application/vnd.ms-excel',
197 'xll' => 'application/vnd.ms-excel',
198 'xlm' => 'application/vnd.ms-excel',
199 'xlt' => 'application/vnd.ms-excel',
200 'xlw' => 'application/vnd.ms-excel',
201 'dbf' => 'application/vnd.ms-excel',
202 'm1v' => 'video/mpeg',
203 'm2v' => 'video/mpeg',
204 'jpgv' => 'video/jpeg',
205 'dvb' => 'video/vnd.dvb.file',
206 'fvt' => 'video/vnd.fvt',
207 'mxu' => 'video/vnd.mpegurl',
208 'pyv' => 'video/vnd.ms-playready.media.pyv',
209 'uvu' => 'video/vnd.uvvu.mp4',
210 'uvvu' => 'video/vnd.uvvu.mp4',
211 'viv' => 'video/vnd.vivo',
212 'fli' => 'video/x-fli',
213 'mk3d' => 'video/x-matroska',
214 'mks' => 'video/x-matroska',
215 'mng' => 'video/x-mng',
216 'asf' => 'video/x-ms-asf',
217 'asx' => 'video/x-ms-asf',
218 'vob' => 'video/x-ms-vob',
219 'wm' => 'video/x-ms-wm',
220 'wmx' => 'video/x-ms-wmx',
221 'wvx' => 'video/x-ms-wvx',
222 'smv' => 'video/x-smv',
223 'mp2a' => 'audio/mpeg',
224 'm2a' => 'audio/mpeg',
225 'm3a' => 'audio/mpeg',
226 'oga' => 'audio/ogg',
227 'spx' => 'audio/ogg',
228 'weba' => 'audio/webm',
229 'm3u8' => 'application/vnd.apple.mpegurl',
230 'ts' => 'video/MP2T',
231 'flp' => 'application/board',
232 'board' => 'application/board',
233 ];
234
235 public static function getMimeTypeList()
236 {
237 return self::$mimes;
238 }
239
240 public static function getExtensionByMimeType(string $mimeType): ?string
241 {
242 $extension = array_search($mimeType, self::$mimes, true);
243
244 return $extension ?: null;
245 }
246
247 public static function getByFileExtension($extension)
248 {
249 $extension = strtolower($extension);
250 if (isset(self::$mimes[$extension]))
251 {
252 return self::$mimes[$extension];
253 }
254
255 return 'application/octet-stream';
256 }
257
258 public static function getByFilename($filename)
259 {
260 return self::getByFileExtension(getFileExtension($filename));
261 }
262
263 public static function getByFilePath($filePath)
264 {
265 $file = new IO\File($filePath);
266
267 return $file->getContentType();
268 }
269
270 public static function getByContent($content)
271 {
272 $fileInfo = new \Finfo(FILEINFO_MIME_TYPE);
273 $mimeType = $fileInfo->buffer($content);
274
275 return $mimeType?: 'application/octet-stream';
276 }
277
278 public static function isImage($mime)
279 {
280 // Attributes are possible: image/jpeg; charset=ISO-8859-1
281 $parts = explode(';', (string)$mime);
282 $mime = trim($parts[0]);
283
284 return preg_match('#^image/[a-z0-9.-]+$#i', $mime);
285 }
286
287 public static function normalize($contentType)
288 {
289 if (!is_string($contentType))
290 {
291 return 'application/octet-stream';
292 }
293
294 $ct = strtolower($contentType);
295 $ct = str_replace(array("\r", "\n", "\0"), "", $ct);
296
297 // We don't need attributes: image/jpeg; charset=ISO-8859-1
298 $parts = explode(';', $ct);
299 $ct = trim($parts[0]);
300
301 if ($ct == '')
302 {
303 $ct = 'application/octet-stream';
304 }
305 elseif (str_contains($ct, "excel"))
306 {
307 $ct = "application/vnd.ms-excel";
308 }
309 elseif (str_contains($ct, "word") && !str_contains($ct, "vnd.openxmlformats"))
310 {
311 $ct = "application/msword";
312 }
313 elseif ($ct == 'image/pjpeg' || $ct == 'image/jpg')
314 {
315 $ct = 'image/jpeg';
316 }
317
318 return $ct;
319 }
320}
static getByContent($content)
Определения mimetype.php:270
static getByFilePath($filePath)
Определения mimetype.php:263
static $mimes
Определения mimetype.php:8
static getByFilename($filename)
Определения mimetype.php:258
static isImage($mime)
Определения mimetype.php:278
static normalize($contentType)
Определения mimetype.php:287
static getExtensionByMimeType(string $mimeType)
Определения mimetype.php:240
static getMimeTypeList()
Определения mimetype.php:235
static getByFileExtension($extension)
Определения mimetype.php:247
$content
Определения commerceml.php:144
$filename
Определения file_edit.php:47
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
Определения Image.php:9
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
$contentType
Определения quickway.php:301