Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

vor 2 Jahren
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532
  1. <?php
  2. namespace Config;
  3. /**
  4. * Mimes
  5. *
  6. * This file contains an array of mime types. It is used by the
  7. * Upload class to help identify allowed file types.
  8. *
  9. * When more than one variation for an extension exist (like jpg, jpeg, etc)
  10. * the most common one should be first in the array to aid the guess*
  11. * methods. The same applies when more than one mime-type exists for a
  12. * single extension.
  13. *
  14. * When working with mime types, please make sure you have the ´fileinfo´
  15. * extension enabled to reliably detect the media types.
  16. */
  17. class Mimes
  18. {
  19. /**
  20. * Map of extensions to mime types.
  21. *
  22. * @var array
  23. */
  24. public static $mimes = [
  25. 'hqx' => [
  26. 'application/mac-binhex40',
  27. 'application/mac-binhex',
  28. 'application/x-binhex40',
  29. 'application/x-mac-binhex40',
  30. ],
  31. 'cpt' => 'application/mac-compactpro',
  32. 'csv' => [
  33. 'text/csv',
  34. 'text/x-comma-separated-values',
  35. 'text/comma-separated-values',
  36. 'application/vnd.ms-excel',
  37. 'application/x-csv',
  38. 'text/x-csv',
  39. 'application/csv',
  40. 'application/excel',
  41. 'application/vnd.msexcel',
  42. 'text/plain',
  43. ],
  44. 'bin' => [
  45. 'application/macbinary',
  46. 'application/mac-binary',
  47. 'application/octet-stream',
  48. 'application/x-binary',
  49. 'application/x-macbinary',
  50. ],
  51. 'dms' => 'application/octet-stream',
  52. 'lha' => 'application/octet-stream',
  53. 'lzh' => 'application/octet-stream',
  54. 'exe' => [
  55. 'application/octet-stream',
  56. 'application/x-msdownload',
  57. ],
  58. 'class' => 'application/octet-stream',
  59. 'psd' => [
  60. 'application/x-photoshop',
  61. 'image/vnd.adobe.photoshop',
  62. ],
  63. 'so' => 'application/octet-stream',
  64. 'sea' => 'application/octet-stream',
  65. 'dll' => 'application/octet-stream',
  66. 'oda' => 'application/oda',
  67. 'pdf' => [
  68. 'application/pdf',
  69. 'application/force-download',
  70. 'application/x-download',
  71. ],
  72. 'ai' => [
  73. 'application/pdf',
  74. 'application/postscript',
  75. ],
  76. 'eps' => 'application/postscript',
  77. 'ps' => 'application/postscript',
  78. 'smi' => 'application/smil',
  79. 'smil' => 'application/smil',
  80. 'mif' => 'application/vnd.mif',
  81. 'xls' => [
  82. 'application/vnd.ms-excel',
  83. 'application/msexcel',
  84. 'application/x-msexcel',
  85. 'application/x-ms-excel',
  86. 'application/x-excel',
  87. 'application/x-dos_ms_excel',
  88. 'application/xls',
  89. 'application/x-xls',
  90. 'application/excel',
  91. 'application/download',
  92. 'application/vnd.ms-office',
  93. 'application/msword',
  94. ],
  95. 'ppt' => [
  96. 'application/vnd.ms-powerpoint',
  97. 'application/powerpoint',
  98. 'application/vnd.ms-office',
  99. 'application/msword',
  100. ],
  101. 'pptx' => [
  102. 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
  103. ],
  104. 'wbxml' => 'application/wbxml',
  105. 'wmlc' => 'application/wmlc',
  106. 'dcr' => 'application/x-director',
  107. 'dir' => 'application/x-director',
  108. 'dxr' => 'application/x-director',
  109. 'dvi' => 'application/x-dvi',
  110. 'gtar' => 'application/x-gtar',
  111. 'gz' => 'application/x-gzip',
  112. 'gzip' => 'application/x-gzip',
  113. 'php' => [
  114. 'application/x-php',
  115. 'application/x-httpd-php',
  116. 'application/php',
  117. 'text/php',
  118. 'text/x-php',
  119. 'application/x-httpd-php-source',
  120. ],
  121. 'php4' => 'application/x-httpd-php',
  122. 'php3' => 'application/x-httpd-php',
  123. 'phtml' => 'application/x-httpd-php',
  124. 'phps' => 'application/x-httpd-php-source',
  125. 'js' => [
  126. 'application/x-javascript',
  127. 'text/plain',
  128. ],
  129. 'swf' => 'application/x-shockwave-flash',
  130. 'sit' => 'application/x-stuffit',
  131. 'tar' => 'application/x-tar',
  132. 'tgz' => [
  133. 'application/x-tar',
  134. 'application/x-gzip-compressed',
  135. ],
  136. 'z' => 'application/x-compress',
  137. 'xhtml' => 'application/xhtml+xml',
  138. 'xht' => 'application/xhtml+xml',
  139. 'zip' => [
  140. 'application/x-zip',
  141. 'application/zip',
  142. 'application/x-zip-compressed',
  143. 'application/s-compressed',
  144. 'multipart/x-zip',
  145. ],
  146. 'rar' => [
  147. 'application/vnd.rar',
  148. 'application/x-rar',
  149. 'application/rar',
  150. 'application/x-rar-compressed',
  151. ],
  152. 'mid' => 'audio/midi',
  153. 'midi' => 'audio/midi',
  154. 'mpga' => 'audio/mpeg',
  155. 'mp2' => 'audio/mpeg',
  156. 'mp3' => [
  157. 'audio/mpeg',
  158. 'audio/mpg',
  159. 'audio/mpeg3',
  160. 'audio/mp3',
  161. ],
  162. 'aif' => [
  163. 'audio/x-aiff',
  164. 'audio/aiff',
  165. ],
  166. 'aiff' => [
  167. 'audio/x-aiff',
  168. 'audio/aiff',
  169. ],
  170. 'aifc' => 'audio/x-aiff',
  171. 'ram' => 'audio/x-pn-realaudio',
  172. 'rm' => 'audio/x-pn-realaudio',
  173. 'rpm' => 'audio/x-pn-realaudio-plugin',
  174. 'ra' => 'audio/x-realaudio',
  175. 'rv' => 'video/vnd.rn-realvideo',
  176. 'wav' => [
  177. 'audio/x-wav',
  178. 'audio/wave',
  179. 'audio/wav',
  180. ],
  181. 'bmp' => [
  182. 'image/bmp',
  183. 'image/x-bmp',
  184. 'image/x-bitmap',
  185. 'image/x-xbitmap',
  186. 'image/x-win-bitmap',
  187. 'image/x-windows-bmp',
  188. 'image/ms-bmp',
  189. 'image/x-ms-bmp',
  190. 'application/bmp',
  191. 'application/x-bmp',
  192. 'application/x-win-bitmap',
  193. ],
  194. 'gif' => 'image/gif',
  195. 'jpg' => [
  196. 'image/jpeg',
  197. 'image/pjpeg',
  198. ],
  199. 'jpeg' => [
  200. 'image/jpeg',
  201. 'image/pjpeg',
  202. ],
  203. 'jpe' => [
  204. 'image/jpeg',
  205. 'image/pjpeg',
  206. ],
  207. 'jp2' => [
  208. 'image/jp2',
  209. 'video/mj2',
  210. 'image/jpx',
  211. 'image/jpm',
  212. ],
  213. 'j2k' => [
  214. 'image/jp2',
  215. 'video/mj2',
  216. 'image/jpx',
  217. 'image/jpm',
  218. ],
  219. 'jpf' => [
  220. 'image/jp2',
  221. 'video/mj2',
  222. 'image/jpx',
  223. 'image/jpm',
  224. ],
  225. 'jpg2' => [
  226. 'image/jp2',
  227. 'video/mj2',
  228. 'image/jpx',
  229. 'image/jpm',
  230. ],
  231. 'jpx' => [
  232. 'image/jp2',
  233. 'video/mj2',
  234. 'image/jpx',
  235. 'image/jpm',
  236. ],
  237. 'jpm' => [
  238. 'image/jp2',
  239. 'video/mj2',
  240. 'image/jpx',
  241. 'image/jpm',
  242. ],
  243. 'mj2' => [
  244. 'image/jp2',
  245. 'video/mj2',
  246. 'image/jpx',
  247. 'image/jpm',
  248. ],
  249. 'mjp2' => [
  250. 'image/jp2',
  251. 'video/mj2',
  252. 'image/jpx',
  253. 'image/jpm',
  254. ],
  255. 'png' => [
  256. 'image/png',
  257. 'image/x-png',
  258. ],
  259. 'webp' => 'image/webp',
  260. 'tif' => 'image/tiff',
  261. 'tiff' => 'image/tiff',
  262. 'css' => [
  263. 'text/css',
  264. 'text/plain',
  265. ],
  266. 'html' => [
  267. 'text/html',
  268. 'text/plain',
  269. ],
  270. 'htm' => [
  271. 'text/html',
  272. 'text/plain',
  273. ],
  274. 'shtml' => [
  275. 'text/html',
  276. 'text/plain',
  277. ],
  278. 'txt' => 'text/plain',
  279. 'text' => 'text/plain',
  280. 'log' => [
  281. 'text/plain',
  282. 'text/x-log',
  283. ],
  284. 'rtx' => 'text/richtext',
  285. 'rtf' => 'text/rtf',
  286. 'xml' => [
  287. 'application/xml',
  288. 'text/xml',
  289. 'text/plain',
  290. ],
  291. 'xsl' => [
  292. 'application/xml',
  293. 'text/xsl',
  294. 'text/xml',
  295. ],
  296. 'mpeg' => 'video/mpeg',
  297. 'mpg' => 'video/mpeg',
  298. 'mpe' => 'video/mpeg',
  299. 'qt' => 'video/quicktime',
  300. 'mov' => 'video/quicktime',
  301. 'avi' => [
  302. 'video/x-msvideo',
  303. 'video/msvideo',
  304. 'video/avi',
  305. 'application/x-troff-msvideo',
  306. ],
  307. 'movie' => 'video/x-sgi-movie',
  308. 'doc' => [
  309. 'application/msword',
  310. 'application/vnd.ms-office',
  311. ],
  312. 'docx' => [
  313. 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
  314. 'application/zip',
  315. 'application/msword',
  316. 'application/x-zip',
  317. ],
  318. 'dot' => [
  319. 'application/msword',
  320. 'application/vnd.ms-office',
  321. ],
  322. 'dotx' => [
  323. 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
  324. 'application/zip',
  325. 'application/msword',
  326. ],
  327. 'xlsx' => [
  328. 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
  329. 'application/zip',
  330. 'application/vnd.ms-excel',
  331. 'application/msword',
  332. 'application/x-zip',
  333. ],
  334. 'xlsb' => 'application/vnd.ms-excel.sheet.binary.macroEnabled.12',
  335. 'xlsm' => 'application/vnd.ms-excel.sheet.macroEnabled.12',
  336. 'word' => [
  337. 'application/msword',
  338. 'application/octet-stream',
  339. ],
  340. 'xl' => 'application/excel',
  341. 'eml' => 'message/rfc822',
  342. 'json' => [
  343. 'application/json',
  344. 'text/json',
  345. ],
  346. 'pem' => [
  347. 'application/x-x509-user-cert',
  348. 'application/x-pem-file',
  349. 'application/octet-stream',
  350. ],
  351. 'p10' => [
  352. 'application/x-pkcs10',
  353. 'application/pkcs10',
  354. ],
  355. 'p12' => 'application/x-pkcs12',
  356. 'p7a' => 'application/x-pkcs7-signature',
  357. 'p7c' => [
  358. 'application/pkcs7-mime',
  359. 'application/x-pkcs7-mime',
  360. ],
  361. 'p7m' => [
  362. 'application/pkcs7-mime',
  363. 'application/x-pkcs7-mime',
  364. ],
  365. 'p7r' => 'application/x-pkcs7-certreqresp',
  366. 'p7s' => 'application/pkcs7-signature',
  367. 'crt' => [
  368. 'application/x-x509-ca-cert',
  369. 'application/x-x509-user-cert',
  370. 'application/pkix-cert',
  371. ],
  372. 'crl' => [
  373. 'application/pkix-crl',
  374. 'application/pkcs-crl',
  375. ],
  376. 'der' => 'application/x-x509-ca-cert',
  377. 'kdb' => 'application/octet-stream',
  378. 'pgp' => 'application/pgp',
  379. 'gpg' => 'application/gpg-keys',
  380. 'sst' => 'application/octet-stream',
  381. 'csr' => 'application/octet-stream',
  382. 'rsa' => 'application/x-pkcs7',
  383. 'cer' => [
  384. 'application/pkix-cert',
  385. 'application/x-x509-ca-cert',
  386. ],
  387. '3g2' => 'video/3gpp2',
  388. '3gp' => [
  389. 'video/3gp',
  390. 'video/3gpp',
  391. ],
  392. 'mp4' => 'video/mp4',
  393. 'm4a' => 'audio/x-m4a',
  394. 'f4v' => [
  395. 'video/mp4',
  396. 'video/x-f4v',
  397. ],
  398. 'flv' => 'video/x-flv',
  399. 'webm' => 'video/webm',
  400. 'aac' => 'audio/x-acc',
  401. 'm4u' => 'application/vnd.mpegurl',
  402. 'm3u' => 'text/plain',
  403. 'xspf' => 'application/xspf+xml',
  404. 'vlc' => 'application/videolan',
  405. 'wmv' => [
  406. 'video/x-ms-wmv',
  407. 'video/x-ms-asf',
  408. ],
  409. 'au' => 'audio/x-au',
  410. 'ac3' => 'audio/ac3',
  411. 'flac' => 'audio/x-flac',
  412. 'ogg' => [
  413. 'audio/ogg',
  414. 'video/ogg',
  415. 'application/ogg',
  416. ],
  417. 'kmz' => [
  418. 'application/vnd.google-earth.kmz',
  419. 'application/zip',
  420. 'application/x-zip',
  421. ],
  422. 'kml' => [
  423. 'application/vnd.google-earth.kml+xml',
  424. 'application/xml',
  425. 'text/xml',
  426. ],
  427. 'ics' => 'text/calendar',
  428. 'ical' => 'text/calendar',
  429. 'zsh' => 'text/x-scriptzsh',
  430. '7zip' => [
  431. 'application/x-compressed',
  432. 'application/x-zip-compressed',
  433. 'application/zip',
  434. 'multipart/x-zip',
  435. ],
  436. 'cdr' => [
  437. 'application/cdr',
  438. 'application/coreldraw',
  439. 'application/x-cdr',
  440. 'application/x-coreldraw',
  441. 'image/cdr',
  442. 'image/x-cdr',
  443. 'zz-application/zz-winassoc-cdr',
  444. ],
  445. 'wma' => [
  446. 'audio/x-ms-wma',
  447. 'video/x-ms-asf',
  448. ],
  449. 'jar' => [
  450. 'application/java-archive',
  451. 'application/x-java-application',
  452. 'application/x-jar',
  453. 'application/x-compressed',
  454. ],
  455. 'svg' => [
  456. 'image/svg+xml',
  457. 'image/svg',
  458. 'application/xml',
  459. 'text/xml',
  460. ],
  461. 'vcf' => 'text/x-vcard',
  462. 'srt' => [
  463. 'text/srt',
  464. 'text/plain',
  465. ],
  466. 'vtt' => [
  467. 'text/vtt',
  468. 'text/plain',
  469. ],
  470. 'ico' => [
  471. 'image/x-icon',
  472. 'image/x-ico',
  473. 'image/vnd.microsoft.icon',
  474. ],
  475. 'stl' => [
  476. 'application/sla',
  477. 'application/vnd.ms-pki.stl',
  478. 'application/x-navistyle',
  479. ],
  480. ];
  481. /**
  482. * Attempts to determine the best mime type for the given file extension.
  483. *
  484. * @return string|null The mime type found, or none if unable to determine.
  485. */
  486. public static function guessTypeFromExtension(string $extension)
  487. {
  488. $extension = trim(strtolower($extension), '. ');
  489. if (! array_key_exists($extension, static::$mimes)) {
  490. return null;
  491. }
  492. return is_array(static::$mimes[$extension]) ? static::$mimes[$extension][0] : static::$mimes[$extension];
  493. }
  494. /**
  495. * Attempts to determine the best file extension for a given mime type.
  496. *
  497. * @param string|null $proposedExtension - default extension (in case there is more than one with the same mime type)
  498. *
  499. * @return string|null The extension determined, or null if unable to match.
  500. */
  501. public static function guessExtensionFromType(string $type, ?string $proposedExtension = null)
  502. {
  503. $type = trim(strtolower($type), '. ');
  504. $proposedExtension = trim(strtolower($proposedExtension ?? ''));
  505. if (
  506. $proposedExtension !== ''
  507. && array_key_exists($proposedExtension, static::$mimes)
  508. && in_array($type, (array) static::$mimes[$proposedExtension], true)
  509. ) {
  510. // The detected mime type matches with the proposed extension.
  511. return $proposedExtension;
  512. }
  513. // Reverse check the mime type list if no extension was proposed.
  514. // This search is order sensitive!
  515. foreach (static::$mimes as $ext => $types) {
  516. if (in_array($type, (array) $types, true)) {
  517. return $ext;
  518. }
  519. }
  520. return null;
  521. }
  522. }