ExtensionMimeTypeGuesser.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928
  1. <?php
  2. namespace Drupal\Core\File\MimeType;
  3. use Drupal\Core\Extension\ModuleHandlerInterface;
  4. use Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesserInterface;
  5. /**
  6. * Makes possible to guess the MIME type of a file using its extension.
  7. */
  8. class ExtensionMimeTypeGuesser implements MimeTypeGuesserInterface {
  9. /**
  10. * Default MIME extension mapping.
  11. *
  12. * @var array
  13. * Array of mimetypes correlated to the extensions that relate to them.
  14. */
  15. protected $defaultMapping = [
  16. 'mimetypes' => [
  17. 0 => 'application/andrew-inset',
  18. 1 => 'application/atom',
  19. 2 => 'application/atomcat+xml',
  20. 3 => 'application/atomserv+xml',
  21. 4 => 'application/cap',
  22. 5 => 'application/cu-seeme',
  23. 6 => 'application/dsptype',
  24. 350 => 'application/epub+zip',
  25. 7 => 'application/hta',
  26. 8 => 'application/java-archive',
  27. 9 => 'application/java-serialized-object',
  28. 10 => 'application/java-vm',
  29. 11 => 'application/mac-binhex40',
  30. 12 => 'application/mathematica',
  31. 13 => 'application/msaccess',
  32. 14 => 'application/msword',
  33. 15 => 'application/octet-stream',
  34. 16 => 'application/oda',
  35. 17 => 'application/ogg',
  36. 18 => 'application/pdf',
  37. 19 => 'application/pgp-keys',
  38. 20 => 'application/pgp-signature',
  39. 21 => 'application/pics-rules',
  40. 22 => 'application/postscript',
  41. 23 => 'application/rar',
  42. 24 => 'application/rdf+xml',
  43. 25 => 'application/rss+xml',
  44. 26 => 'application/rtf',
  45. 27 => 'application/smil',
  46. 349 => 'application/vnd.amazon.ebook',
  47. 28 => 'application/vnd.cinderella',
  48. 29 => 'application/vnd.google-earth.kml+xml',
  49. 30 => 'application/vnd.google-earth.kmz',
  50. 31 => 'application/vnd.mozilla.xul+xml',
  51. 32 => 'application/vnd.ms-excel',
  52. 33 => 'application/vnd.ms-excel.addin.macroEnabled.12',
  53. 34 => 'application/vnd.ms-excel.sheet.binary.macroEnabled.12',
  54. 35 => 'application/vnd.ms-excel.sheet.macroEnabled.12',
  55. 36 => 'application/vnd.ms-excel.template.macroEnabled.12',
  56. 37 => 'application/vnd.ms-pki.seccat',
  57. 38 => 'application/vnd.ms-pki.stl',
  58. 39 => 'application/vnd.ms-powerpoint',
  59. 40 => 'application/vnd.ms-powerpoint.addin.macroEnabled.12',
  60. 41 => 'application/vnd.ms-powerpoint.presentation.macroEnabled.12',
  61. 42 => 'application/vnd.ms-powerpoint.slideshow.macroEnabled.12',
  62. 43 => 'application/vnd.ms-powerpoint.template.macroEnabled.12',
  63. 44 => 'application/vnd.ms-word.document.macroEnabled.12',
  64. 45 => 'application/vnd.ms-word.template.macroEnabled.12',
  65. 46 => 'application/vnd.ms-xpsdocument',
  66. 47 => 'application/vnd.oasis.opendocument.chart',
  67. 48 => 'application/vnd.oasis.opendocument.database',
  68. 49 => 'application/vnd.oasis.opendocument.formula',
  69. 50 => 'application/vnd.oasis.opendocument.graphics',
  70. 51 => 'application/vnd.oasis.opendocument.graphics-template',
  71. 52 => 'application/vnd.oasis.opendocument.image',
  72. 53 => 'application/vnd.oasis.opendocument.presentation',
  73. 54 => 'application/vnd.oasis.opendocument.presentation-template',
  74. 55 => 'application/vnd.oasis.opendocument.spreadsheet',
  75. 56 => 'application/vnd.oasis.opendocument.spreadsheet-template',
  76. 57 => 'application/vnd.oasis.opendocument.text',
  77. 58 => 'application/vnd.oasis.opendocument.text-master',
  78. 59 => 'application/vnd.oasis.opendocument.text-template',
  79. 60 => 'application/vnd.oasis.opendocument.text-web',
  80. 61 => 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
  81. 62 => 'application/vnd.openxmlformats-officedocument.presentationml.slideshow',
  82. 63 => 'application/vnd.openxmlformats-officedocument.presentationml.template',
  83. 64 => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
  84. 65 => 'application/vnd.openxmlformats-officedocument.spreadsheetml.template',
  85. 66 => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
  86. 67 => 'application/vnd.openxmlformats-officedocument.wordprocessingml.template',
  87. 68 => 'application/vnd.rim.cod',
  88. 69 => 'application/vnd.smaf',
  89. 70 => 'application/vnd.stardivision.calc',
  90. 71 => 'application/vnd.stardivision.chart',
  91. 72 => 'application/vnd.stardivision.draw',
  92. 73 => 'application/vnd.stardivision.impress',
  93. 74 => 'application/vnd.stardivision.math',
  94. 75 => 'application/vnd.stardivision.writer',
  95. 76 => 'application/vnd.stardivision.writer-global',
  96. 77 => 'application/vnd.sun.xml.calc',
  97. 78 => 'application/vnd.sun.xml.calc.template',
  98. 79 => 'application/vnd.sun.xml.draw',
  99. 80 => 'application/vnd.sun.xml.draw.template',
  100. 81 => 'application/vnd.sun.xml.impress',
  101. 82 => 'application/vnd.sun.xml.impress.template',
  102. 83 => 'application/vnd.sun.xml.math',
  103. 84 => 'application/vnd.sun.xml.writer',
  104. 85 => 'application/vnd.sun.xml.writer.global',
  105. 86 => 'application/vnd.sun.xml.writer.template',
  106. 87 => 'application/vnd.symbian.install',
  107. 88 => 'application/vnd.visio',
  108. 89 => 'application/vnd.wap.wbxml',
  109. 90 => 'application/vnd.wap.wmlc',
  110. 91 => 'application/vnd.wap.wmlscriptc',
  111. 92 => 'application/wordperfect',
  112. 93 => 'application/wordperfect5.1',
  113. 94 => 'application/x-123',
  114. 95 => 'application/x-7z-compressed',
  115. 96 => 'application/x-abiword',
  116. 97 => 'application/x-apple-diskimage',
  117. 98 => 'application/x-bcpio',
  118. 99 => 'application/x-bittorrent',
  119. 100 => 'application/x-cab',
  120. 101 => 'application/x-cbr',
  121. 102 => 'application/x-cbz',
  122. 103 => 'application/x-cdf',
  123. 104 => 'application/x-cdlink',
  124. 105 => 'application/x-chess-pgn',
  125. 106 => 'application/x-cpio',
  126. 107 => 'application/x-debian-package',
  127. 108 => 'application/x-director',
  128. 109 => 'application/x-dms',
  129. 110 => 'application/x-doom',
  130. 111 => 'application/x-dvi',
  131. 112 => 'application/x-flac',
  132. 113 => 'application/x-font',
  133. 114 => 'application/x-freemind',
  134. 115 => 'application/x-futuresplash',
  135. 116 => 'application/x-gnumeric',
  136. 117 => 'application/x-go-sgf',
  137. 118 => 'application/x-graphing-calculator',
  138. 119 => 'application/x-gtar',
  139. 120 => 'application/x-hdf',
  140. 121 => 'application/x-httpd-eruby',
  141. 122 => 'application/x-httpd-php',
  142. 123 => 'application/x-httpd-php-source',
  143. 124 => 'application/x-httpd-php3',
  144. 125 => 'application/x-httpd-php3-preprocessed',
  145. 126 => 'application/x-httpd-php4',
  146. 127 => 'application/x-ica',
  147. 128 => 'application/x-internet-signup',
  148. 129 => 'application/x-iphone',
  149. 130 => 'application/x-iso9660-image',
  150. 131 => 'application/x-java-jnlp-file',
  151. 132 => 'application/javascript',
  152. 133 => 'application/x-jmol',
  153. 134 => 'application/x-kchart',
  154. 135 => 'application/x-killustrator',
  155. 136 => 'application/x-koan',
  156. 137 => 'application/x-kpresenter',
  157. 138 => 'application/x-kspread',
  158. 139 => 'application/x-kword',
  159. 140 => 'application/x-latex',
  160. 141 => 'application/x-lha',
  161. 142 => 'application/x-lyx',
  162. 143 => 'application/x-lzh',
  163. 144 => 'application/x-lzx',
  164. 145 => 'application/x-maker',
  165. 146 => 'application/x-mif',
  166. 351 => 'application/x-mobipocket-ebook',
  167. 352 => 'application/x-mobipocket-ebook',
  168. 147 => 'application/x-ms-wmd',
  169. 148 => 'application/x-ms-wmz',
  170. 149 => 'application/x-msdos-program',
  171. 150 => 'application/x-msi',
  172. 151 => 'application/x-netcdf',
  173. 152 => 'application/x-ns-proxy-autoconfig',
  174. 153 => 'application/x-nwc',
  175. 154 => 'application/x-object',
  176. 155 => 'application/x-oz-application',
  177. 156 => 'application/x-pkcs7-certreqresp',
  178. 157 => 'application/x-pkcs7-crl',
  179. 158 => 'application/x-python-code',
  180. 159 => 'application/x-quicktimeplayer',
  181. 160 => 'application/x-redhat-package-manager',
  182. 161 => 'application/x-shar',
  183. 162 => 'application/x-shockwave-flash',
  184. 163 => 'application/x-stuffit',
  185. 164 => 'application/x-sv4cpio',
  186. 165 => 'application/x-sv4crc',
  187. 166 => 'application/x-tar',
  188. 167 => 'application/x-tcl',
  189. 168 => 'application/x-tex-gf',
  190. 169 => 'application/x-tex-pk',
  191. 170 => 'application/x-texinfo',
  192. 171 => 'application/x-trash',
  193. 172 => 'application/x-troff',
  194. 173 => 'application/x-troff-man',
  195. 174 => 'application/x-troff-me',
  196. 175 => 'application/x-troff-ms',
  197. 176 => 'application/x-ustar',
  198. 177 => 'application/x-wais-source',
  199. 178 => 'application/x-wingz',
  200. 179 => 'application/x-x509-ca-cert',
  201. 180 => 'application/x-xcf',
  202. 181 => 'application/x-xfig',
  203. 182 => 'application/x-xpinstall',
  204. 183 => 'application/xhtml+xml',
  205. 184 => 'application/xml',
  206. 185 => 'application/zip',
  207. 186 => 'audio/basic',
  208. 187 => 'audio/midi',
  209. 346 => 'audio/mp4',
  210. 188 => 'audio/mpeg',
  211. 189 => 'audio/ogg',
  212. 190 => 'audio/prs.sid',
  213. 356 => 'audio/webm',
  214. 191 => 'audio/x-aiff',
  215. 192 => 'audio/x-gsm',
  216. 354 => 'audio/x-matroska',
  217. 193 => 'audio/x-mpegurl',
  218. 194 => 'audio/x-ms-wax',
  219. 195 => 'audio/x-ms-wma',
  220. 196 => 'audio/x-pn-realaudio',
  221. 197 => 'audio/x-realaudio',
  222. 198 => 'audio/x-scpls',
  223. 199 => 'audio/x-sd2',
  224. 200 => 'audio/x-wav',
  225. 201 => 'chemical/x-alchemy',
  226. 202 => 'chemical/x-cache',
  227. 203 => 'chemical/x-cache-csf',
  228. 204 => 'chemical/x-cactvs-binary',
  229. 205 => 'chemical/x-cdx',
  230. 206 => 'chemical/x-cerius',
  231. 207 => 'chemical/x-chem3d',
  232. 208 => 'chemical/x-chemdraw',
  233. 209 => 'chemical/x-cif',
  234. 210 => 'chemical/x-cmdf',
  235. 211 => 'chemical/x-cml',
  236. 212 => 'chemical/x-compass',
  237. 213 => 'chemical/x-crossfire',
  238. 214 => 'chemical/x-csml',
  239. 215 => 'chemical/x-ctx',
  240. 216 => 'chemical/x-cxf',
  241. 217 => 'chemical/x-embl-dl-nucleotide',
  242. 218 => 'chemical/x-galactic-spc',
  243. 219 => 'chemical/x-gamess-input',
  244. 220 => 'chemical/x-gaussian-checkpoint',
  245. 221 => 'chemical/x-gaussian-cube',
  246. 222 => 'chemical/x-gaussian-input',
  247. 223 => 'chemical/x-gaussian-log',
  248. 224 => 'chemical/x-gcg8-sequence',
  249. 225 => 'chemical/x-genbank',
  250. 226 => 'chemical/x-hin',
  251. 227 => 'chemical/x-isostar',
  252. 228 => 'chemical/x-jcamp-dx',
  253. 229 => 'chemical/x-kinemage',
  254. 230 => 'chemical/x-macmolecule',
  255. 231 => 'chemical/x-macromodel-input',
  256. 232 => 'chemical/x-mdl-molfile',
  257. 233 => 'chemical/x-mdl-rdfile',
  258. 234 => 'chemical/x-mdl-rxnfile',
  259. 235 => 'chemical/x-mdl-sdfile',
  260. 236 => 'chemical/x-mdl-tgf',
  261. 237 => 'chemical/x-mmcif',
  262. 238 => 'chemical/x-mol2',
  263. 239 => 'chemical/x-molconn-Z',
  264. 240 => 'chemical/x-mopac-graph',
  265. 241 => 'chemical/x-mopac-input',
  266. 242 => 'chemical/x-mopac-out',
  267. 243 => 'chemical/x-mopac-vib',
  268. 244 => 'chemical/x-ncbi-asn1-ascii',
  269. 245 => 'chemical/x-ncbi-asn1-binary',
  270. 246 => 'chemical/x-ncbi-asn1-spec',
  271. 247 => 'chemical/x-pdb',
  272. 248 => 'chemical/x-rosdal',
  273. 249 => 'chemical/x-swissprot',
  274. 250 => 'chemical/x-vamas-iso14976',
  275. 251 => 'chemical/x-vmd',
  276. 252 => 'chemical/x-xtel',
  277. 253 => 'chemical/x-xyz',
  278. 254 => 'image/gif',
  279. 255 => 'image/ief',
  280. 256 => 'image/jpeg',
  281. 257 => 'image/pcx',
  282. 258 => 'image/png',
  283. 259 => 'image/svg+xml',
  284. 260 => 'image/tiff',
  285. 261 => 'image/vnd.djvu',
  286. 262 => 'image/vnd.microsoft.icon',
  287. 263 => 'image/vnd.wap.wbmp',
  288. 355 => 'image/webp',
  289. 264 => 'image/x-cmu-raster',
  290. 265 => 'image/x-coreldraw',
  291. 266 => 'image/x-coreldrawpattern',
  292. 267 => 'image/x-coreldrawtemplate',
  293. 268 => 'image/x-corelphotopaint',
  294. 269 => 'image/x-jg',
  295. 270 => 'image/x-jng',
  296. 271 => 'image/x-ms-bmp',
  297. 272 => 'image/x-photoshop',
  298. 273 => 'image/x-portable-anymap',
  299. 274 => 'image/x-portable-bitmap',
  300. 275 => 'image/x-portable-graymap',
  301. 276 => 'image/x-portable-pixmap',
  302. 277 => 'image/x-rgb',
  303. 278 => 'image/x-xbitmap',
  304. 279 => 'image/x-xpixmap',
  305. 280 => 'image/x-xwindowdump',
  306. 281 => 'message/rfc822',
  307. 282 => 'model/iges',
  308. 283 => 'model/mesh',
  309. 284 => 'model/vrml',
  310. 285 => 'text/calendar',
  311. 286 => 'text/css',
  312. 287 => 'text/csv',
  313. 288 => 'text/h323',
  314. 289 => 'text/html',
  315. 290 => 'text/iuls',
  316. 291 => 'text/mathml',
  317. 292 => 'text/plain',
  318. 293 => 'text/richtext',
  319. 294 => 'text/scriptlet',
  320. 295 => 'text/tab-separated-values',
  321. 296 => 'text/texmacs',
  322. 297 => 'text/vnd.sun.j2me.app-descriptor',
  323. 298 => 'text/vnd.wap.wml',
  324. 299 => 'text/vnd.wap.wmlscript',
  325. 358 => 'text/vtt',
  326. 300 => 'text/x-bibtex',
  327. 301 => 'text/x-boo',
  328. 302 => 'text/x-c++hdr',
  329. 303 => 'text/x-c++src',
  330. 304 => 'text/x-chdr',
  331. 305 => 'text/x-component',
  332. 306 => 'text/x-csh',
  333. 307 => 'text/x-csrc',
  334. 308 => 'text/x-diff',
  335. 309 => 'text/x-dsrc',
  336. 310 => 'text/x-haskell',
  337. 311 => 'text/x-java',
  338. 312 => 'text/x-literate-haskell',
  339. 313 => 'text/x-moc',
  340. 314 => 'text/x-pascal',
  341. 315 => 'text/x-pcs-gcd',
  342. 316 => 'text/x-perl',
  343. 317 => 'text/x-python',
  344. 318 => 'text/x-setext',
  345. 319 => 'text/x-sh',
  346. 320 => 'text/x-tcl',
  347. 321 => 'text/x-tex',
  348. 322 => 'text/x-vcalendar',
  349. 323 => 'text/x-vcard',
  350. 324 => 'video/3gpp',
  351. 325 => 'video/dl',
  352. 326 => 'video/dv',
  353. 327 => 'video/fli',
  354. 328 => 'video/gl',
  355. 329 => 'video/mp4',
  356. 330 => 'video/mpeg',
  357. 331 => 'video/ogg',
  358. 332 => 'video/quicktime',
  359. 333 => 'video/vnd.mpegurl',
  360. 357 => 'video/webm',
  361. 347 => 'video/x-flv',
  362. 334 => 'video/x-la-asf',
  363. 348 => 'video/x-m4v',
  364. 353 => 'video/x-matroska',
  365. 335 => 'video/x-mng',
  366. 336 => 'video/x-ms-asf',
  367. 337 => 'video/x-ms-wm',
  368. 338 => 'video/x-ms-wmv',
  369. 339 => 'video/x-ms-wmx',
  370. 340 => 'video/x-ms-wvx',
  371. 341 => 'video/x-msvideo',
  372. 342 => 'video/x-sgi-movie',
  373. 343 => 'x-conference/x-cooltalk',
  374. 344 => 'x-epoc/x-sisx-app',
  375. 345 => 'x-world/x-vrml',
  376. ],
  377. // Extensions added to this list MUST be lower-case.
  378. 'extensions' => [
  379. 'ez' => 0,
  380. 'atom' => 1,
  381. 'atomcat' => 2,
  382. 'atomsrv' => 3,
  383. 'cap' => 4,
  384. 'pcap' => 4,
  385. 'cu' => 5,
  386. 'tsp' => 6,
  387. 'hta' => 7,
  388. 'jar' => 8,
  389. 'ser' => 9,
  390. 'class' => 10,
  391. 'hqx' => 11,
  392. 'nb' => 12,
  393. 'mdb' => 13,
  394. 'dot' => 14,
  395. 'doc' => 14,
  396. 'bin' => 15,
  397. 'oda' => 16,
  398. 'ogx' => 17,
  399. 'pdf' => 18,
  400. 'key' => 19,
  401. 'pgp' => 20,
  402. 'prf' => 21,
  403. 'eps' => 22,
  404. 'ai' => 22,
  405. 'ps' => 22,
  406. 'rar' => 23,
  407. 'rdf' => 24,
  408. 'rss' => 25,
  409. 'rtf' => 26,
  410. 'smi' => 27,
  411. 'smil' => 27,
  412. 'cdy' => 28,
  413. 'kml' => 29,
  414. 'kmz' => 30,
  415. 'xul' => 31,
  416. 'xlb' => 32,
  417. 'xlt' => 32,
  418. 'xls' => 32,
  419. 'xlam' => 33,
  420. 'xlsb' => 34,
  421. 'xlsm' => 35,
  422. 'xltm' => 36,
  423. 'cat' => 37,
  424. 'stl' => 38,
  425. 'pps' => 39,
  426. 'ppt' => 39,
  427. 'ppam' => 40,
  428. 'pptm' => 41,
  429. 'ppsm' => 42,
  430. 'potm' => 43,
  431. 'docm' => 44,
  432. 'dotm' => 45,
  433. 'xps' => 46,
  434. 'odc' => 47,
  435. 'odb' => 48,
  436. 'odf' => 49,
  437. 'odg' => 50,
  438. 'otg' => 51,
  439. 'odi' => 52,
  440. 'odp' => 53,
  441. 'otp' => 54,
  442. 'ods' => 55,
  443. 'ots' => 56,
  444. 'odt' => 57,
  445. 'odm' => 58,
  446. 'ott' => 59,
  447. 'oth' => 60,
  448. 'pptx' => 61,
  449. 'ppsx' => 62,
  450. 'potx' => 63,
  451. 'xlsx' => 64,
  452. 'xltx' => 65,
  453. 'docx' => 66,
  454. 'dotx' => 67,
  455. 'cod' => 68,
  456. 'mmf' => 69,
  457. 'sdc' => 70,
  458. 'sds' => 71,
  459. 'sda' => 72,
  460. 'sdd' => 73,
  461. 'sdw' => 75,
  462. 'sgl' => 76,
  463. 'sxc' => 77,
  464. 'stc' => 78,
  465. 'sxd' => 79,
  466. 'std' => 80,
  467. 'sxi' => 81,
  468. 'sti' => 82,
  469. 'sxm' => 83,
  470. 'sxw' => 84,
  471. 'sxg' => 85,
  472. 'stw' => 86,
  473. 'sis' => 87,
  474. 'vsd' => 88,
  475. 'wbxml' => 89,
  476. 'wmlc' => 90,
  477. 'wmlsc' => 91,
  478. 'wpd' => 92,
  479. 'wp5' => 93,
  480. 'wk' => 94,
  481. '7z' => 95,
  482. 'abw' => 96,
  483. 'dmg' => 97,
  484. 'bcpio' => 98,
  485. 'torrent' => 99,
  486. 'cab' => 100,
  487. 'cbr' => 101,
  488. 'cbz' => 102,
  489. 'cdf' => 103,
  490. 'vcd' => 104,
  491. 'pgn' => 105,
  492. 'cpio' => 106,
  493. 'udeb' => 107,
  494. 'deb' => 107,
  495. 'dir' => 108,
  496. 'dxr' => 108,
  497. 'dcr' => 108,
  498. 'dms' => 109,
  499. 'wad' => 110,
  500. 'dvi' => 111,
  501. 'flac' => 112,
  502. 'pfa' => 113,
  503. 'pfb' => 113,
  504. 'pcf' => 113,
  505. 'gsf' => 113,
  506. 'pcf.z' => 113,
  507. 'mm' => 114,
  508. 'spl' => 115,
  509. 'gnumeric' => 116,
  510. 'sgf' => 117,
  511. 'gcf' => 118,
  512. 'taz' => 119,
  513. 'gtar' => 119,
  514. 'tgz' => 119,
  515. 'hdf' => 120,
  516. 'rhtml' => 121,
  517. 'phtml' => 122,
  518. 'pht' => 122,
  519. 'php' => 122,
  520. 'phps' => 123,
  521. 'php3' => 124,
  522. 'php3p' => 125,
  523. 'php4' => 126,
  524. 'ica' => 127,
  525. 'ins' => 128,
  526. 'isp' => 128,
  527. 'iii' => 129,
  528. 'iso' => 130,
  529. 'jnlp' => 131,
  530. 'js' => 132,
  531. 'jmz' => 133,
  532. 'chrt' => 134,
  533. 'kil' => 135,
  534. 'skp' => 136,
  535. 'skd' => 136,
  536. 'skm' => 136,
  537. 'skt' => 136,
  538. 'kpr' => 137,
  539. 'kpt' => 137,
  540. 'ksp' => 138,
  541. 'kwd' => 139,
  542. 'kwt' => 139,
  543. 'latex' => 140,
  544. 'lha' => 141,
  545. 'lyx' => 142,
  546. 'lzh' => 143,
  547. 'lzx' => 144,
  548. 'maker' => 145,
  549. 'frm' => 145,
  550. 'frame' => 145,
  551. 'fm' => 145,
  552. 'book' => 145,
  553. 'fb' => 145,
  554. 'fbdoc' => 145,
  555. 'mif' => 146,
  556. 'wmd' => 147,
  557. 'wmz' => 148,
  558. 'dll' => 149,
  559. 'bat' => 149,
  560. 'exe' => 149,
  561. 'com' => 149,
  562. 'msi' => 150,
  563. 'nc' => 151,
  564. 'pac' => 152,
  565. 'nwc' => 153,
  566. 'o' => 154,
  567. 'oza' => 155,
  568. 'p7r' => 156,
  569. 'crl' => 157,
  570. 'pyo' => 158,
  571. 'pyc' => 158,
  572. 'qtl' => 159,
  573. 'rpm' => 160,
  574. 'shar' => 161,
  575. 'swf' => 162,
  576. 'swfl' => 162,
  577. 'sitx' => 163,
  578. 'sit' => 163,
  579. 'sv4cpio' => 164,
  580. 'sv4crc' => 165,
  581. 'tar' => 166,
  582. 'gf' => 168,
  583. 'pk' => 169,
  584. 'texi' => 170,
  585. 'texinfo' => 170,
  586. 'sik' => 171,
  587. '~' => 171,
  588. 'bak' => 171,
  589. '%' => 171,
  590. 'old' => 171,
  591. 't' => 172,
  592. 'roff' => 172,
  593. 'tr' => 172,
  594. 'man' => 173,
  595. 'me' => 174,
  596. 'ms' => 175,
  597. 'ustar' => 176,
  598. 'src' => 177,
  599. 'wz' => 178,
  600. 'crt' => 179,
  601. 'xcf' => 180,
  602. 'fig' => 181,
  603. 'xpi' => 182,
  604. 'xht' => 183,
  605. 'xhtml' => 183,
  606. 'xml' => 184,
  607. 'xsl' => 184,
  608. 'zip' => 185,
  609. 'au' => 186,
  610. 'snd' => 186,
  611. 'mid' => 187,
  612. 'midi' => 187,
  613. 'kar' => 187,
  614. 'mpega' => 188,
  615. 'mpga' => 188,
  616. 'm4a' => 188,
  617. 'mp3' => 188,
  618. 'mp2' => 188,
  619. 'ogg' => 189,
  620. 'oga' => 189,
  621. 'spx' => 189,
  622. 'sid' => 190,
  623. 'aif' => 191,
  624. 'aiff' => 191,
  625. 'aifc' => 191,
  626. 'gsm' => 192,
  627. 'm3u' => 193,
  628. 'wax' => 194,
  629. 'wma' => 195,
  630. 'rm' => 196,
  631. 'ram' => 196,
  632. 'ra' => 197,
  633. 'pls' => 198,
  634. 'sd2' => 199,
  635. 'wav' => 200,
  636. 'alc' => 201,
  637. 'cac' => 202,
  638. 'cache' => 202,
  639. 'csf' => 203,
  640. 'cascii' => 204,
  641. 'cbin' => 204,
  642. 'ctab' => 204,
  643. 'cdx' => 205,
  644. 'cer' => 206,
  645. 'c3d' => 207,
  646. 'chm' => 208,
  647. 'cif' => 209,
  648. 'cmdf' => 210,
  649. 'cml' => 211,
  650. 'cpa' => 212,
  651. 'bsd' => 213,
  652. 'csml' => 214,
  653. 'csm' => 214,
  654. 'ctx' => 215,
  655. 'cxf' => 216,
  656. 'cef' => 216,
  657. 'emb' => 217,
  658. 'embl' => 217,
  659. 'spc' => 218,
  660. 'gam' => 219,
  661. 'inp' => 219,
  662. 'gamin' => 219,
  663. 'fchk' => 220,
  664. 'fch' => 220,
  665. 'cub' => 221,
  666. 'gau' => 222,
  667. 'gjf' => 222,
  668. 'gjc' => 222,
  669. 'gal' => 223,
  670. 'gcg' => 224,
  671. 'gen' => 225,
  672. 'hin' => 226,
  673. 'istr' => 227,
  674. 'ist' => 227,
  675. 'dx' => 228,
  676. 'jdx' => 228,
  677. 'kin' => 229,
  678. 'mcm' => 230,
  679. 'mmd' => 231,
  680. 'mmod' => 231,
  681. 'mol' => 232,
  682. 'rd' => 233,
  683. 'rxn' => 234,
  684. 'sdf' => 235,
  685. 'sd' => 235,
  686. 'tgf' => 236,
  687. 'mcif' => 237,
  688. 'mol2' => 238,
  689. 'b' => 239,
  690. 'gpt' => 240,
  691. 'mopcrt' => 241,
  692. 'zmt' => 241,
  693. 'mpc' => 241,
  694. 'dat' => 241,
  695. 'mop' => 241,
  696. 'moo' => 242,
  697. 'mvb' => 243,
  698. 'prt' => 244,
  699. 'aso' => 245,
  700. 'val' => 245,
  701. 'asn' => 246,
  702. 'ent' => 247,
  703. 'pdb' => 247,
  704. 'ros' => 248,
  705. 'sw' => 249,
  706. 'vms' => 250,
  707. 'vmd' => 251,
  708. 'xtel' => 252,
  709. 'xyz' => 253,
  710. 'gif' => 254,
  711. 'ief' => 255,
  712. 'jpeg' => 256,
  713. 'jpe' => 256,
  714. 'jpg' => 256,
  715. 'pcx' => 257,
  716. 'png' => 258,
  717. 'svgz' => 259,
  718. 'svg' => 259,
  719. 'tif' => 260,
  720. 'tiff' => 260,
  721. 'djvu' => 261,
  722. 'djv' => 261,
  723. 'ico' => 262,
  724. 'wbmp' => 263,
  725. 'ras' => 264,
  726. 'cdr' => 265,
  727. 'pat' => 266,
  728. 'cdt' => 267,
  729. 'cpt' => 268,
  730. 'art' => 269,
  731. 'jng' => 270,
  732. 'bmp' => 271,
  733. 'psd' => 272,
  734. 'pnm' => 273,
  735. 'pbm' => 274,
  736. 'pgm' => 275,
  737. 'ppm' => 276,
  738. 'rgb' => 277,
  739. 'xbm' => 278,
  740. 'xpm' => 279,
  741. 'xwd' => 280,
  742. 'eml' => 281,
  743. 'igs' => 282,
  744. 'iges' => 282,
  745. 'silo' => 283,
  746. 'msh' => 283,
  747. 'mesh' => 283,
  748. 'icz' => 285,
  749. 'ics' => 285,
  750. 'css' => 286,
  751. 'csv' => 287,
  752. '323' => 288,
  753. 'html' => 289,
  754. 'htm' => 289,
  755. 'shtml' => 289,
  756. 'uls' => 290,
  757. 'mml' => 291,
  758. 'txt' => 292,
  759. 'pot' => 292,
  760. 'text' => 292,
  761. 'asc' => 292,
  762. 'rtx' => 293,
  763. 'wsc' => 294,
  764. 'sct' => 294,
  765. 'tsv' => 295,
  766. 'ts' => 296,
  767. 'tm' => 296,
  768. 'jad' => 297,
  769. 'wml' => 298,
  770. 'wmls' => 299,
  771. 'bib' => 300,
  772. 'boo' => 301,
  773. 'hpp' => 302,
  774. 'hh' => 302,
  775. 'h++' => 302,
  776. 'hxx' => 302,
  777. 'cxx' => 303,
  778. 'cc' => 303,
  779. 'cpp' => 303,
  780. 'c++' => 303,
  781. 'h' => 304,
  782. 'htc' => 305,
  783. 'csh' => 306,
  784. 'c' => 307,
  785. 'patch' => 308,
  786. 'diff' => 308,
  787. 'd' => 309,
  788. 'hs' => 310,
  789. 'java' => 311,
  790. 'lhs' => 312,
  791. 'moc' => 313,
  792. 'pas' => 314,
  793. 'p' => 314,
  794. 'gcd' => 315,
  795. 'pm' => 316,
  796. 'pl' => 316,
  797. 'py' => 317,
  798. 'etx' => 318,
  799. 'sh' => 319,
  800. 'tk' => 320,
  801. 'tcl' => 320,
  802. 'cls' => 321,
  803. 'ltx' => 321,
  804. 'sty' => 321,
  805. 'tex' => 321,
  806. 'vcs' => 322,
  807. 'vcf' => 323,
  808. '3gp' => 324,
  809. 'dl' => 325,
  810. 'dif' => 326,
  811. 'dv' => 326,
  812. 'fli' => 327,
  813. 'gl' => 328,
  814. 'mp4' => 329,
  815. 'f4v' => 329,
  816. 'f4p' => 329,
  817. 'mpe' => 330,
  818. 'mpeg' => 330,
  819. 'mpg' => 330,
  820. 'ogv' => 331,
  821. 'qt' => 332,
  822. 'mov' => 332,
  823. 'mxu' => 333,
  824. 'lsf' => 334,
  825. 'lsx' => 334,
  826. 'mng' => 335,
  827. 'asx' => 336,
  828. 'asf' => 336,
  829. 'wm' => 337,
  830. 'wmv' => 338,
  831. 'wmx' => 339,
  832. 'wvx' => 340,
  833. 'avi' => 341,
  834. 'movie' => 342,
  835. 'ice' => 343,
  836. 'sisx' => 344,
  837. 'wrl' => 345,
  838. 'vrm' => 345,
  839. 'vrml' => 345,
  840. 'f4a' => 346,
  841. 'f4b' => 346,
  842. 'flv' => 347,
  843. 'm4v' => 348,
  844. 'azw' => 349,
  845. 'epub' => 350,
  846. 'mobi' => 351,
  847. 'prc' => 352,
  848. 'mkv' => 353,
  849. 'mka' => 354,
  850. 'webp' => 355,
  851. 'weba' => 356,
  852. 'webm' => 357,
  853. 'vtt' => 358,
  854. ],
  855. ];
  856. /**
  857. * The MIME types mapping array after going through the module handler.
  858. *
  859. * @var array
  860. */
  861. protected $mapping;
  862. /**
  863. * The module handler.
  864. *
  865. * @var \Drupal\Core\Extension\ModuleHandlerInterface
  866. */
  867. protected $moduleHandler;
  868. /**
  869. * Constructs a new ExtensionMimeTypeGuesser.
  870. *
  871. * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
  872. * The module handler.
  873. */
  874. public function __construct(ModuleHandlerInterface $module_handler) {
  875. $this->moduleHandler = $module_handler;
  876. }
  877. /**
  878. * {@inheritdoc}
  879. */
  880. public function guess($path) {
  881. if ($this->mapping === NULL) {
  882. $mapping = $this->defaultMapping;
  883. // Allow modules to alter the default mapping.
  884. $this->moduleHandler->alter('file_mimetype_mapping', $mapping);
  885. $this->mapping = $mapping;
  886. }
  887. $extension = '';
  888. $file_parts = explode('.', drupal_basename($path));
  889. // Remove the first part: a full filename should not match an extension.
  890. array_shift($file_parts);
  891. // Iterate over the file parts, trying to find a match.
  892. // For my.awesome.image.jpeg, we try:
  893. // - jpeg
  894. // - image.jpeg, and
  895. // - awesome.image.jpeg
  896. while ($additional_part = array_pop($file_parts)) {
  897. $extension = strtolower($additional_part . ($extension ? '.' . $extension : ''));
  898. if (isset($this->mapping['extensions'][$extension])) {
  899. return $this->mapping['mimetypes'][$this->mapping['extensions'][$extension]];
  900. }
  901. }
  902. return 'application/octet-stream';
  903. }
  904. /**
  905. * Sets the mimetypes/extension mapping to use when guessing mimetype.
  906. *
  907. * @param array|null $mapping
  908. * Passing a NULL mapping will cause guess() to use self::$defaultMapping.
  909. */
  910. public function setMapping(array $mapping = NULL) {
  911. $this->mapping = $mapping;
  912. }
  913. }