MimeLib.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829
  1. <?php
  2. App::uses('CakeResponse', 'Network');
  3. /**
  4. * Wrapper to be able to read cake core's mime types as well as fix for missing ones
  5. *
  6. * @version 1.0
  7. * @license http://opensource.org/licenses/mit-license.php MIT
  8. * @author Mark Scherer
  9. */
  10. class MimeLib extends CakeResponse {
  11. protected $_mimeTypesExt = [
  12. '3dm' => 'x-world/x-3dmf',
  13. '3dmf' => 'x-world/x-3dmf',
  14. 'a' => 'application/octet-stream',
  15. 'aab' => 'application/x-authorware-bin',
  16. 'aam' => 'application/x-authorware-map',
  17. 'aas' => 'application/x-authorware-seg',
  18. 'abc' => 'text/vnd.abc',
  19. 'acgi' => 'text/html',
  20. 'afl' => 'video/animaflex',
  21. 'ai' => 'application/postscript',
  22. 'aif' => 'audio/aiff',
  23. 'aif' => 'audio/x-aiff',
  24. 'aifc' => 'audio/aiff',
  25. 'aifc' => 'audio/x-aiff',
  26. 'aiff' => 'audio/aiff',
  27. 'aiff' => 'audio/x-aiff',
  28. 'aim' => 'application/x-aim',
  29. 'aip' => 'text/x-audiosoft-intra',
  30. 'ani' => 'application/x-navi-animation',
  31. 'aos' => 'application/x-nokia-9000-communicator-add-on-software',
  32. 'aps' => 'application/mime',
  33. 'arc' => 'application/octet-stream',
  34. 'arj' => 'application/arj',
  35. 'arj' => 'application/octet-stream',
  36. 'art' => 'image/x-jg',
  37. 'asf' => 'video/x-ms-asf',
  38. 'asm' => 'text/x-asm',
  39. 'asp' => 'text/asp',
  40. 'asx' => 'application/x-mplayer2',
  41. 'asx' => 'video/x-ms-asf',
  42. 'asx' => 'video/x-ms-asf-plugin',
  43. 'au' => 'audio/basic',
  44. 'au' => 'audio/x-au',
  45. 'avi' => 'application/x-troff-msvideo',
  46. 'avi' => 'video/avi',
  47. 'avi' => 'video/msvideo',
  48. 'avi' => 'video/x-msvideo',
  49. 'avs' => 'video/avs-video',
  50. 'bcpio' => 'application/x-bcpio',
  51. 'bin' => 'application/mac-binary',
  52. 'bin' => 'application/macbinary',
  53. 'bin' => 'application/octet-stream',
  54. 'bin' => 'application/x-binary',
  55. 'bin' => 'application/x-macbinary',
  56. 'bm' => 'image/bmp',
  57. 'bmp' => 'image/bmp',
  58. 'bmp' => 'image/x-windows-bmp',
  59. 'boo' => 'application/book',
  60. 'book' => 'application/book',
  61. 'boz' => 'application/x-bzip2',
  62. 'bsh' => 'application/x-bsh',
  63. 'bz' => 'application/x-bzip',
  64. 'bz2' => 'application/x-bzip2',
  65. 'c' => 'text/plain',
  66. 'c' => 'text/x-c',
  67. 'c++' => 'text/plain',
  68. 'cat' => 'application/vnd.ms-pki.seccat',
  69. 'cc' => 'text/plain',
  70. 'cc' => 'text/x-c',
  71. 'ccad' => 'application/clariscad',
  72. 'cco' => 'application/x-cocoa',
  73. 'cdf' => 'application/cdf',
  74. 'cdf' => 'application/x-cdf',
  75. 'cdf' => 'application/x-netcdf',
  76. 'cer' => 'application/pkix-cert',
  77. 'cer' => 'application/x-x509-ca-cert',
  78. 'cha' => 'application/x-chat',
  79. 'chat' => 'application/x-chat',
  80. 'class' => 'application/java',
  81. 'class' => 'application/java-byte-code',
  82. 'class' => 'application/x-java-class',
  83. 'com' => 'application/octet-stream',
  84. 'com' => 'text/plain',
  85. 'conf' => 'text/plain',
  86. 'cpio' => 'application/x-cpio',
  87. 'cpp' => 'text/x-c',
  88. 'cpt' => 'application/mac-compactpro',
  89. 'cpt' => 'application/x-compactpro',
  90. 'cpt' => 'application/x-cpt',
  91. 'crl' => 'application/pkcs-crl',
  92. 'crl' => 'application/pkix-crl',
  93. 'crt' => 'application/pkix-cert',
  94. 'crt' => 'application/x-x509-ca-cert',
  95. 'crt' => 'application/x-x509-user-cert',
  96. 'csh' => 'application/x-csh',
  97. 'csh' => 'text/x-script.csh',
  98. 'css' => 'application/x-pointplus',
  99. 'css' => 'text/css',
  100. 'cxx' => 'text/plain',
  101. 'dcr' => 'application/x-director',
  102. 'deepv' => 'application/x-deepv',
  103. 'def' => 'text/plain',
  104. 'der' => 'application/x-x509-ca-cert',
  105. 'dif' => 'video/x-dv',
  106. 'dir' => 'application/x-director',
  107. 'dl' => 'video/dl',
  108. 'dl' => 'video/x-dl',
  109. 'doc' => 'application/msword',
  110. 'dot' => 'application/msword',
  111. 'dp' => 'application/commonground',
  112. 'drw' => 'application/drafting',
  113. 'dump' => 'application/octet-stream',
  114. 'dv' => 'video/x-dv',
  115. 'dvi' => 'application/x-dvi',
  116. 'dwf' => 'model/vnd.dwf',
  117. 'dwg' => 'application/acad',
  118. 'dwg' => 'image/vnd.dwg',
  119. 'dwg' => 'image/x-dwg',
  120. 'dxf' => 'application/dxf',
  121. 'dxf' => 'image/vnd.dwg',
  122. 'dxf' => 'image/x-dwg',
  123. 'dxr' => 'application/x-director',
  124. 'el' => 'text/x-script.elisp',
  125. 'elc' => 'application/x-bytecode.elisp',
  126. 'elc' => 'application/x-elc',
  127. 'env' => 'application/x-envoy',
  128. 'eps' => 'application/postscript',
  129. 'es' => 'application/x-esrehber',
  130. 'etx' => 'text/x-setext',
  131. 'evy' => 'application/envoy',
  132. 'evy' => 'application/x-envoy',
  133. 'exe' => 'application/octet-stream',
  134. 'f' => 'text/plain',
  135. 'f' => 'text/x-fortran',
  136. 'f77' => 'text/x-fortran',
  137. 'f90' => 'text/plain',
  138. 'f90' => 'text/x-fortran',
  139. 'fdf' => 'application/vnd.fdf',
  140. 'fif' => 'application/fractals',
  141. 'fif' => 'image/fif',
  142. 'fli' => 'video/fli',
  143. 'fli' => 'video/x-fli',
  144. 'flo' => 'image/florian',
  145. 'flx' => 'text/vnd.fmi.flexstor',
  146. 'fmf' => 'video/x-atomic3d-feature',
  147. 'for' => 'text/plain',
  148. 'for' => 'text/x-fortran',
  149. 'fpx' => 'image/vnd.fpx',
  150. 'fpx' => 'image/vnd.net-fpx',
  151. 'frl' => 'application/freeloader',
  152. 'funk' => 'audio/make',
  153. 'g' => 'text/plain',
  154. 'g3' => 'image/g3fax',
  155. 'gif' => 'image/gif',
  156. 'gl' => 'video/gl',
  157. 'gl' => 'video/x-gl',
  158. 'gsd' => 'audio/x-gsm',
  159. 'gsm' => 'audio/x-gsm',
  160. 'gsp' => 'application/x-gsp',
  161. 'gss' => 'application/x-gss',
  162. 'gtar' => 'application/x-gtar',
  163. 'gz' => 'application/x-compressed',
  164. 'gz' => 'application/x-gzip',
  165. 'gzip' => 'application/x-gzip',
  166. 'gzip' => 'multipart/x-gzip',
  167. 'h' => 'text/plain',
  168. 'h' => 'text/x-h',
  169. 'hdf' => 'application/x-hdf',
  170. 'help' => 'application/x-helpfile',
  171. 'hgl' => 'application/vnd.hp-hpgl',
  172. 'hh' => 'text/plain',
  173. 'hh' => 'text/x-h',
  174. 'hlb' => 'text/x-script',
  175. 'hlp' => 'application/hlp',
  176. 'hlp' => 'application/x-helpfile',
  177. 'hlp' => 'application/x-winhelp',
  178. 'hpg' => 'application/vnd.hp-hpgl',
  179. 'hpgl' => 'application/vnd.hp-hpgl',
  180. 'hqx' => 'application/binhex',
  181. 'hqx' => 'application/binhex4',
  182. 'hqx' => 'application/mac-binhex',
  183. 'hqx' => 'application/mac-binhex40',
  184. 'hqx' => 'application/x-binhex40',
  185. 'hqx' => 'application/x-mac-binhex40',
  186. 'hta' => 'application/hta',
  187. 'htc' => 'text/x-component',
  188. 'htmls' => 'text/html',
  189. 'htt' => 'text/webviewhtml',
  190. 'htx' => 'text/html',
  191. 'ice' => 'x-conference/x-cooltalk',
  192. 'ico' => 'image/x-icon',
  193. 'ics' => 'application/ics', // important for ipad to properly display ics files
  194. 'ical' => 'text/calendar',
  195. 'idc' => 'text/plain',
  196. 'ief' => 'image/ief',
  197. 'iefs' => 'image/ief',
  198. 'ifb' => 'text/calendar',
  199. 'iges' => 'application/iges',
  200. 'iges' => 'model/iges',
  201. 'igs' => 'application/iges',
  202. 'igs' => 'model/iges',
  203. 'ima' => 'application/x-ima',
  204. 'imap' => 'application/x-httpd-imap',
  205. 'inf' => 'application/inf',
  206. 'ins' => 'application/x-internett-signup',
  207. 'ip' => 'application/x-ip2',
  208. 'isu' => 'video/x-isvideo',
  209. 'it' => 'audio/it',
  210. 'iv' => 'application/x-inventor',
  211. 'ivr' => 'i-world/i-vrml',
  212. 'ivy' => 'application/x-livescreen',
  213. 'jam' => 'audio/x-jam',
  214. 'jav' => 'text/plain',
  215. 'jav' => 'text/x-java-source',
  216. 'java' => 'text/plain',
  217. 'java' => 'text/x-java-source',
  218. 'jcm' => 'application/x-java-commerce',
  219. 'jfif' => 'image/jpeg',
  220. 'jfif' => 'image/pjpeg',
  221. 'jfif-tbnl' => 'image/jpeg',
  222. 'jpe' => 'image/jpeg',
  223. 'jpe' => 'image/pjpeg',
  224. 'jpeg' => 'image/jpeg',
  225. 'jpeg' => 'image/pjpeg',
  226. 'jpg' => 'image/jpeg',
  227. 'jpg' => 'image/pjpeg',
  228. 'jps' => 'image/x-jps',
  229. 'js' => 'text/javascript',
  230. 'jut' => 'image/jutvision',
  231. 'kar' => 'audio/midi',
  232. 'kar' => 'music/x-karaoke',
  233. 'ksh' => 'application/x-ksh',
  234. 'ksh' => 'text/x-script.ksh',
  235. 'la' => 'audio/nspaudio',
  236. 'la' => 'audio/x-nspaudio',
  237. 'lam' => 'audio/x-liveaudio',
  238. 'latex' => 'application/x-latex',
  239. 'lha' => 'application/lha',
  240. 'lha' => 'application/octet-stream',
  241. 'lha' => 'application/x-lha',
  242. 'lhx' => 'application/octet-stream',
  243. 'list' => 'text/plain',
  244. 'lma' => 'audio/nspaudio',
  245. 'lma' => 'audio/x-nspaudio',
  246. 'log' => 'text/plain',
  247. 'lsp' => 'application/x-lisp',
  248. 'lsp' => 'text/x-script.lisp',
  249. 'lst' => 'text/plain',
  250. 'lsx' => 'text/x-la-asf',
  251. 'ltx' => 'application/x-latex',
  252. 'lzh' => 'application/octet-stream',
  253. 'lzh' => 'application/x-lzh',
  254. 'lzx' => 'application/lzx',
  255. 'lzx' => 'application/octet-stream',
  256. 'lzx' => 'application/x-lzx',
  257. 'm' => 'text/plain',
  258. 'm' => 'text/x-m',
  259. 'm1v' => 'video/mpeg',
  260. 'm2a' => 'audio/mpeg',
  261. 'm2v' => 'video/mpeg',
  262. 'm3u' => 'audio/x-mpequrl',
  263. 'man' => 'application/x-troff-man',
  264. 'map' => 'application/x-navimap',
  265. 'mar' => 'text/plain',
  266. 'mbd' => 'application/mbedlet',
  267. 'mc$' => 'application/x-magic-cap-package-1.0',
  268. 'mcd' => 'application/mcad',
  269. 'mcd' => 'application/x-mathcad',
  270. 'mcf' => 'image/vasa',
  271. 'mcf' => 'text/mcf',
  272. 'mcp' => 'application/netmc',
  273. 'me' => 'application/x-troff-me',
  274. 'mht' => 'message/rfc822',
  275. 'mhtml' => 'message/rfc822',
  276. 'mid' => 'application/x-midi',
  277. 'mid' => 'audio/midi',
  278. 'mid' => 'audio/x-mid',
  279. 'mid' => 'audio/x-midi',
  280. 'mid' => 'music/crescendo',
  281. 'mid' => 'x-music/x-midi',
  282. 'midi' => 'application/x-midi',
  283. 'midi' => 'audio/midi',
  284. 'midi' => 'audio/x-mid',
  285. 'midi' => 'audio/x-midi',
  286. 'midi' => 'music/crescendo',
  287. 'midi' => 'x-music/x-midi',
  288. 'mif' => 'application/x-frame',
  289. 'mif' => 'application/x-mif',
  290. 'mime' => 'message/rfc822',
  291. 'mime' => 'www/mime',
  292. 'mjf' => 'audio/x-vnd.audioexplosion.mjuicemediafile',
  293. 'mjpg' => 'video/x-motion-jpeg',
  294. 'mm' => 'application/base64',
  295. 'mm' => 'application/x-meme',
  296. 'mme' => 'application/base64',
  297. 'mod' => 'audio/mod',
  298. 'mod' => 'audio/x-mod',
  299. 'moov' => 'video/quicktime',
  300. 'mov' => 'video/quicktime',
  301. 'movie' => 'video/x-sgi-movie',
  302. 'mp2' => 'audio/mpeg',
  303. 'mp2' => 'audio/x-mpeg',
  304. 'mp2' => 'video/mpeg',
  305. 'mp2' => 'video/x-mpeg',
  306. 'mp2' => 'video/x-mpeq2a',
  307. 'mp3' => 'audio/mpeg3',
  308. 'mp3' => 'audio/x-mpeg-3',
  309. 'mp3' => 'video/mpeg',
  310. 'mp3' => 'video/x-mpeg',
  311. 'mpa' => 'audio/mpeg',
  312. 'mpa' => 'video/mpeg',
  313. 'mpc' => 'application/x-project',
  314. 'mpe' => 'video/mpeg',
  315. 'mpeg' => 'video/mpeg',
  316. 'mpg' => 'audio/mpeg',
  317. 'mpg' => 'video/mpeg',
  318. 'mpga' => 'audio/mpeg',
  319. 'mpp' => 'application/vnd.ms-project',
  320. 'mpt' => 'application/x-project',
  321. 'mpv' => 'application/x-project',
  322. 'mpx' => 'application/x-project',
  323. 'mrc' => 'application/marc',
  324. 'ms' => 'application/x-troff-ms',
  325. 'mv' => 'video/x-sgi-movie',
  326. 'my' => 'audio/make',
  327. 'mzz' => 'application/x-vnd.audioexplosion.mzz',
  328. 'nap' => 'image/naplps',
  329. 'naplps' => 'image/naplps',
  330. 'nc' => 'application/x-netcdf',
  331. 'ncm' => 'application/vnd.nokia.configuration-message',
  332. 'nif' => 'image/x-niff',
  333. 'niff' => 'image/x-niff',
  334. 'nix' => 'application/x-mix-transfer',
  335. 'nsc' => 'application/x-conference',
  336. 'nvd' => 'application/x-navidoc',
  337. 'o' => 'application/octet-stream',
  338. 'oda' => 'application/oda',
  339. 'omc' => 'application/x-omc',
  340. 'omcd' => 'application/x-omcdatamaker',
  341. 'omcr' => 'application/x-omcregerator',
  342. 'p' => 'text/x-pascal',
  343. 'p10' => 'application/pkcs10',
  344. 'p10' => 'application/x-pkcs10',
  345. 'p12' => 'application/pkcs-12',
  346. 'p12' => 'application/x-pkcs12',
  347. 'p7a' => 'application/x-pkcs7-signature',
  348. 'p7c' => 'application/pkcs7-mime',
  349. 'p7c' => 'application/x-pkcs7-mime',
  350. 'p7m' => 'application/pkcs7-mime',
  351. 'p7m' => 'application/x-pkcs7-mime',
  352. 'p7r' => 'application/x-pkcs7-certreqresp',
  353. 'p7s' => 'application/pkcs7-signature',
  354. 'part' => 'application/pro_eng',
  355. 'pas' => 'text/pascal',
  356. 'pbm' => 'image/x-portable-bitmap',
  357. 'pcl' => 'application/vnd.hp-pcl',
  358. 'pcl' => 'application/x-pcl',
  359. 'pct' => 'image/x-pict',
  360. 'pcx' => 'image/x-pcx',
  361. 'pdb' => 'chemical/x-pdb',
  362. 'pdf' => 'application/pdf',
  363. 'pfunk' => 'audio/make',
  364. 'pfunk' => 'audio/make.my.funk',
  365. 'pgm' => 'image/x-portable-graymap',
  366. 'pgm' => 'image/x-portable-greymap',
  367. 'pic' => 'image/pict',
  368. 'pict' => 'image/pict',
  369. 'pkg' => 'application/x-newton-compatible-pkg',
  370. 'pko' => 'application/vnd.ms-pki.pko',
  371. 'pl' => 'text/plain',
  372. 'pl' => 'text/x-script.perl',
  373. 'plx' => 'application/x-pixclscript',
  374. 'pm' => 'image/x-xpixmap',
  375. 'pm' => 'text/x-script.perl-module',
  376. 'pm4' => 'application/x-pagemaker',
  377. 'pm5' => 'application/x-pagemaker',
  378. 'png' => 'image/png',
  379. 'pnm' => 'application/x-portable-anymap',
  380. 'pnm' => 'image/x-portable-anymap',
  381. 'pot' => 'application/mspowerpoint',
  382. 'pot' => 'application/vnd.ms-powerpoint',
  383. 'pov' => 'model/x-pov',
  384. 'ppa' => 'application/vnd.ms-powerpoint',
  385. 'ppm' => 'image/x-portable-pixmap',
  386. 'pps' => 'application/mspowerpoint',
  387. 'pps' => 'application/vnd.ms-powerpoint',
  388. 'ppt' => 'application/mspowerpoint',
  389. 'ppt' => 'application/powerpoint',
  390. 'ppt' => 'application/vnd.ms-powerpoint',
  391. 'ppt' => 'application/x-mspowerpoint',
  392. 'ppz' => 'application/mspowerpoint',
  393. 'pre' => 'application/x-freelance',
  394. 'prt' => 'application/pro_eng',
  395. 'ps' => 'application/postscript',
  396. 'psd' => 'application/octet-stream',
  397. 'pvu' => 'paleovu/x-pv',
  398. 'pwz' => 'application/vnd.ms-powerpoint',
  399. 'py' => 'text/x-script.phyton',
  400. 'pyc' => 'applicaiton/x-bytecode.python',
  401. 'qcp' => 'audio/vnd.qcelp',
  402. 'qd3' => 'x-world/x-3dmf',
  403. 'qd3d' => 'x-world/x-3dmf',
  404. 'qif' => 'image/x-quicktime',
  405. 'qt' => 'video/quicktime',
  406. 'qtc' => 'video/x-qtc',
  407. 'qti' => 'image/x-quicktime',
  408. 'qtif' => 'image/x-quicktime',
  409. 'ra' => 'audio/x-pn-realaudio',
  410. 'ra' => 'audio/x-pn-realaudio-plugin',
  411. 'ra' => 'audio/x-realaudio',
  412. 'ram' => 'audio/x-pn-realaudio',
  413. 'ras' => 'application/x-cmu-raster',
  414. 'ras' => 'image/cmu-raster',
  415. 'ras' => 'image/x-cmu-raster',
  416. 'rast' => 'image/cmu-raster',
  417. 'rexx' => 'text/x-script.rexx',
  418. 'rf' => 'image/vnd.rn-realflash',
  419. 'rgb' => 'image/x-rgb',
  420. 'rm' => 'application/vnd.rn-realmedia',
  421. 'rm' => 'audio/x-pn-realaudio',
  422. 'rmi' => 'audio/mid',
  423. 'rmm' => 'audio/x-pn-realaudio',
  424. 'rmp' => 'audio/x-pn-realaudio',
  425. 'rmp' => 'audio/x-pn-realaudio-plugin',
  426. 'rng' => 'application/ringing-tones',
  427. 'rng' => 'application/vnd.nokia.ringing-tone',
  428. 'rnx' => 'application/vnd.rn-realplayer',
  429. 'roff' => 'application/x-troff',
  430. 'rp' => 'image/vnd.rn-realpix',
  431. 'rpm' => 'audio/x-pn-realaudio-plugin',
  432. 'rt' => 'text/richtext',
  433. 'rt' => 'text/vnd.rn-realtext',
  434. 'rtf' => 'application/rtf',
  435. 'rtf' => 'application/x-rtf',
  436. 'rtf' => 'text/richtext',
  437. 'rtx' => 'application/rtf',
  438. 'rtx' => 'text/richtext',
  439. 'rv' => 'video/vnd.rn-realvideo',
  440. 's' => 'text/x-asm',
  441. 's3m' => 'audio/s3m',
  442. 'saveme' => 'application/octet-stream',
  443. 'sbk' => 'application/x-tbook',
  444. 'scm' => 'application/x-lotusscreencam',
  445. 'scm' => 'text/x-script.guile',
  446. 'scm' => 'text/x-script.scheme',
  447. 'scm' => 'video/x-scm',
  448. 'sdml' => 'text/plain',
  449. 'sdp' => 'application/sdp',
  450. 'sdp' => 'application/x-sdp',
  451. 'sdr' => 'application/sounder',
  452. 'sea' => 'application/sea',
  453. 'sea' => 'application/x-sea',
  454. 'set' => 'application/set',
  455. 'sgm' => 'text/sgml',
  456. 'sgm' => 'text/x-sgml',
  457. 'sgml' => 'text/sgml',
  458. 'sgml' => 'text/x-sgml',
  459. 'sh' => 'application/x-bsh',
  460. 'sh' => 'application/x-sh',
  461. 'sh' => 'application/x-shar',
  462. 'sh' => 'text/x-script.sh',
  463. 'shar' => 'application/x-bsh',
  464. 'shar' => 'application/x-shar',
  465. 'shtml' => 'text/html',
  466. 'sid' => 'audio/x-psid',
  467. 'sit' => 'application/x-sit',
  468. 'sit' => 'application/x-stuffit',
  469. 'skd' => 'application/x-koan',
  470. 'skm' => 'application/x-koan',
  471. 'skp' => 'application/x-koan',
  472. 'skt' => 'application/x-koan',
  473. 'sl' => 'application/x-seelogo',
  474. 'smi' => 'application/smil',
  475. 'smil' => 'application/smil',
  476. 'snd' => 'audio/basic',
  477. 'snd' => 'audio/x-adpcm',
  478. 'sol' => 'application/solids',
  479. 'spc' => 'application/x-pkcs7-certificates',
  480. 'spc' => 'text/x-speech',
  481. 'spl' => 'application/futuresplash',
  482. 'spr' => 'application/x-sprite',
  483. 'sprite' => 'application/x-sprite',
  484. 'src' => 'application/x-wais-source',
  485. 'ssi' => 'text/x-server-parsed-html',
  486. 'ssm' => 'application/streamingmedia',
  487. 'sst' => 'application/vnd.ms-pki.certstore',
  488. 'step' => 'application/step',
  489. 'stl' => 'application/sla',
  490. 'stl' => 'application/vnd.ms-pki.stl',
  491. 'stl' => 'application/x-navistyle',
  492. 'stp' => 'application/step',
  493. 'sv4cpio' => 'application/x-sv4cpio',
  494. 'sv4crc' => 'application/x-sv4crc',
  495. 'svf' => 'image/vnd.dwg',
  496. 'svf' => 'image/x-dwg',
  497. 'svr' => 'application/x-world',
  498. 'svr' => 'x-world/x-svr',
  499. 'swf' => 'application/x-shockwave-flash',
  500. 't' => 'application/x-troff',
  501. 'talk' => 'text/x-speech',
  502. 'tar' => 'application/x-tar',
  503. 'tbk' => 'application/toolbook',
  504. 'tbk' => 'application/x-tbook',
  505. 'tcl' => 'application/x-tcl',
  506. 'tcl' => 'text/x-script.tcl',
  507. 'tcsh' => 'text/x-script.tcsh',
  508. 'tex' => 'application/x-tex',
  509. 'texi' => 'application/x-texinfo',
  510. 'texinfo' => 'application/x-texinfo',
  511. 'text' => 'application/plain',
  512. 'text' => 'text/plain',
  513. 'tgz' => 'application/gnutar',
  514. 'tgz' => 'application/x-compressed',
  515. 'tif' => 'image/tiff',
  516. 'tif' => 'image/x-tiff',
  517. 'tiff' => 'image/tiff',
  518. 'tiff' => 'image/x-tiff',
  519. 'tr' => 'application/x-troff',
  520. 'tsi' => 'audio/tsp-audio',
  521. 'tsp' => 'application/dsptype',
  522. 'tsp' => 'audio/tsplayer',
  523. 'tsv' => 'text/tab-separated-values',
  524. 'turbot' => 'image/florian',
  525. 'txt' => 'text/plain',
  526. 'uil' => 'text/x-uil',
  527. 'uni' => 'text/uri-list',
  528. 'unis' => 'text/uri-list',
  529. 'unv' => 'application/i-deas',
  530. 'uri' => 'text/uri-list',
  531. 'uris' => 'text/uri-list',
  532. 'ustar' => 'application/x-ustar',
  533. 'ustar' => 'multipart/x-ustar',
  534. 'uu' => 'application/octet-stream',
  535. 'uu' => 'text/x-uuencode',
  536. 'uue' => 'text/x-uuencode',
  537. 'vcd' => 'application/x-cdlink',
  538. 'vcs' => 'text/x-vcalendar',
  539. 'vda' => 'application/vda',
  540. 'vdo' => 'video/vdo',
  541. 'vew' => 'application/groupwise',
  542. 'viv' => 'video/vivo',
  543. 'viv' => 'video/vnd.vivo',
  544. 'vivo' => 'video/vivo',
  545. 'vivo' => 'video/vnd.vivo',
  546. 'vmd' => 'application/vocaltec-media-desc',
  547. 'vmf' => 'application/vocaltec-media-file',
  548. 'voc' => 'audio/voc',
  549. 'voc' => 'audio/x-voc',
  550. 'vos' => 'video/vosaic',
  551. 'vox' => 'audio/voxware',
  552. 'vqe' => 'audio/x-twinvq-plugin',
  553. 'vqf' => 'audio/x-twinvq',
  554. 'vql' => 'audio/x-twinvq-plugin',
  555. 'vrml' => 'application/x-vrml',
  556. 'vrml' => 'model/vrml',
  557. 'vrml' => 'x-world/x-vrml',
  558. 'vrt' => 'x-world/x-vrt',
  559. 'vsd' => 'application/x-visio',
  560. 'vst' => 'application/x-visio',
  561. 'vsw' => 'application/x-visio',
  562. 'w60' => 'application/wordperfect6.0',
  563. 'w61' => 'application/wordperfect6.1',
  564. 'w6w' => 'application/msword',
  565. 'wav' => 'audio/wav',
  566. 'wav' => 'audio/x-wav',
  567. 'wb1' => 'application/x-qpro',
  568. 'wbmp' => 'image/vnd.wap.wbmp',
  569. 'web' => 'application/vnd.xara',
  570. 'wiz' => 'application/msword',
  571. 'wk1' => 'application/x-123',
  572. 'wmf' => 'windows/metafile',
  573. 'wml' => 'text/vnd.wap.wml',
  574. 'wmlc' => 'application/vnd.wap.wmlc',
  575. 'wmls' => 'text/vnd.wap.wmlscript',
  576. 'wmlsc' => 'application/vnd.wap.wmlscriptc',
  577. 'word' => 'application/msword',
  578. 'wp' => 'application/wordperfect',
  579. 'wp5' => 'application/wordperfect',
  580. 'wp5' => 'application/wordperfect6.0',
  581. 'wp6' => 'application/wordperfect',
  582. 'wpd' => 'application/wordperfect',
  583. 'wpd' => 'application/x-wpwin',
  584. 'wq1' => 'application/x-lotus',
  585. 'wri' => 'application/mswrite',
  586. 'wri' => 'application/x-wri',
  587. 'wrl' => 'application/x-world',
  588. 'wrl' => 'model/vrml',
  589. 'wrl' => 'x-world/x-vrml',
  590. 'wrz' => 'model/vrml',
  591. 'wrz' => 'x-world/x-vrml',
  592. 'wsc' => 'text/scriplet',
  593. 'wsrc' => 'application/x-wais-source',
  594. 'wtk' => 'application/x-wintalk',
  595. 'xbm' => 'image/x-xbitmap',
  596. 'xbm' => 'image/x-xbm',
  597. 'xbm' => 'image/xbm',
  598. 'xdr' => 'video/x-amt-demorun',
  599. 'xgz' => 'xgl/drawing',
  600. 'xif' => 'image/vnd.xiff',
  601. 'xl' => 'application/excel',
  602. 'xla' => 'application/excel',
  603. 'xla' => 'application/x-excel',
  604. 'xla' => 'application/x-msexcel',
  605. 'xlb' => 'application/excel',
  606. 'xlb' => 'application/vnd.ms-excel',
  607. 'xlb' => 'application/x-excel',
  608. 'xlc' => 'application/excel',
  609. 'xlc' => 'application/vnd.ms-excel',
  610. 'xlc' => 'application/x-excel',
  611. 'xld' => 'application/excel',
  612. 'xld' => 'application/x-excel',
  613. 'xlk' => 'application/excel',
  614. 'xlk' => 'application/x-excel',
  615. 'xll' => 'application/excel',
  616. 'xll' => 'application/vnd.ms-excel',
  617. 'xll' => 'application/x-excel',
  618. 'xlm' => 'application/excel',
  619. 'xlm' => 'application/vnd.ms-excel',
  620. 'xlm' => 'application/x-excel',
  621. 'xls' => 'application/excel',
  622. 'xls' => 'application/vnd.ms-excel',
  623. 'xls' => 'application/x-excel',
  624. 'xls' => 'application/x-msexcel',
  625. 'xlt' => 'application/excel',
  626. 'xlt' => 'application/x-excel',
  627. 'xlv' => 'application/excel',
  628. 'xlv' => 'application/x-excel',
  629. 'xlw' => 'application/excel',
  630. 'xlw' => 'application/vnd.ms-excel',
  631. 'xlw' => 'application/x-excel',
  632. 'xlw' => 'application/x-msexcel',
  633. 'xm' => 'audio/xm',
  634. 'xml' => 'application/xml',
  635. 'xml' => 'text/xml',
  636. 'xmz' => 'xgl/movie',
  637. 'xpix' => 'application/x-vnd.ls-xpix',
  638. 'xpm' => 'image/x-xpixmap',
  639. 'xpm' => 'image/xpm',
  640. 'x-png' => 'image/png',
  641. 'xsr' => 'video/x-amt-showrun',
  642. 'xwd' => 'image/x-xwd',
  643. 'xwd' => 'image/x-xwindowdump',
  644. 'xyz' => 'chemical/x-pdb',
  645. 'z' => ['application/x-compress', 'application/x-compressed'],
  646. 'zip' => 'application/x-compressed',
  647. 'zip' => 'application/x-zip-compressed',
  648. 'zip' => 'application/zip',
  649. 'zip' => 'multipart/x-zip',
  650. 'zoo' => 'application/octet-stream',
  651. 'zsh' => 'text/x-script.zsh',
  652. 'txt' => 'text/plain',
  653. 'php' => 'application/x-httpd-php',
  654. 'phps' => 'application/x-httpd-phps',
  655. 'css' => 'text/css',
  656. 'js' => 'application/javascript',
  657. 'json' => 'application/json',
  658. 'xml' => 'application/xml',
  659. 'swf' => 'application/x-shockwave-flash',
  660. 'flv' => 'video/x-flv',
  661. 'asc' => 'text/plain',
  662. 'atom' => 'application/atom+xml',
  663. 'bcpio' => 'application/x-bcpio',
  664. 'png' => 'image/png',
  665. 'jpe' => 'image/jpeg',
  666. 'jpeg' => 'image/jpeg',
  667. 'jpg' => 'image/jpeg',
  668. 'gif' => 'image/gif',
  669. 'bmp' => 'image/bmp',
  670. 'ico' => 'image/vnd.microsoft.icon',
  671. 'tiff' => 'image/tiff',
  672. 'tif' => 'image/tiff',
  673. 'svg' => 'image/svg+xml',
  674. 'svgz' => 'image/svg+xml',
  675. 'zip' => 'application/zip',
  676. 'rar' => 'application/x-rar-compressed',
  677. 'exe' => 'application/x-msdownload',
  678. 'msi' => 'application/x-msdownload',
  679. 'cab' => 'application/vnd.ms-cab-compressed',
  680. 'mp3' => 'audio/mpeg',
  681. 'qt' => 'video/quicktime',
  682. 'mov' => 'video/quicktime',
  683. 'au' => 'audio/basic',
  684. 'avi' => 'video/x-msvideo',
  685. 'pdf' => 'application/pdf',
  686. 'psd' => 'image/vnd.adobe.photoshop',
  687. 'ai' => 'application/postscript',
  688. 'eps' => 'application/postscript',
  689. 'ps' => 'application/postscript',
  690. 'aif' => 'audio/x-aiff',
  691. 'aifc' => 'audio/x-aiff',
  692. 'aiff' => 'audio/x-aiff',
  693. 'doc' => 'application/msword',
  694. 'rtf' => 'application/rtf',
  695. 'xls' => 'application/vnd.ms-excel',
  696. 'ppt' => 'application/vnd.ms-powerpoint',
  697. 'odt' => 'application/vnd.oasis.opendocument.text',
  698. 'ods' => 'application/vnd.oasis.opendocument.spreadsheet',
  699. 'swf' => ['application/x-shockwave-flash', 'application/x-shockwave-flash2-preview', 'application/futuresplash', 'image/vnd.rn-realflash']
  700. ];
  701. /**
  702. * Override constructor
  703. */
  704. public function __construct() {
  705. }
  706. /**
  707. * Get all mime types that are supported right now
  708. *
  709. * @return array
  710. */
  711. public function getMimeTypes($coreHasPrecedence = false) {
  712. if ($coreHasPrecedence) {
  713. return $this->_mimeTypes += $this->_mimeTypesExt;
  714. }
  715. return $this->_mimeTypesExt += $this->_mimeTypes;
  716. }
  717. /**
  718. * Returns the primary mime type definition for an alias
  719. *
  720. * e.g `getMimeType('pdf'); // returns 'application/pdf'`
  721. *
  722. * @param string $alias the content type alias to map
  723. * @param bool $primaryOnly
  724. * @param bool $coreHasPrecedence
  725. * @return mixed string mapped mime type or false if $alias is not mapped
  726. */
  727. public function getMimeType($alias, $primaryOnly = true, $coreHasPrecedence = false) {
  728. if (empty($this->_mimeTypeTmp)) {
  729. $this->_mimeTypesTmp = $this->getMimeTypes($coreHasPrecedence);
  730. }
  731. if (!isset($this->_mimeTypesTmp[$alias])) {
  732. return false;
  733. }
  734. $mimeType = $this->_mimeTypesTmp[$alias];
  735. if ($primaryOnly && is_array($mimeType)) {
  736. $mimeType = array_shift($mimeType);
  737. }
  738. return $mimeType;
  739. }
  740. /**
  741. * Maps a content-type back to an alias
  742. *
  743. * e.g `mapType('application/pdf'); // returns 'pdf'`
  744. *
  745. * @param mixed $ctype Either a string content type to map, or an array of types.
  746. * @return mixed Aliases for the types provided.
  747. */
  748. public function mapType($ctype) {
  749. return parent::mapType($ctype);
  750. }
  751. /**
  752. * Retrieve the corresponding MIME type, if one exists
  753. *
  754. * @param String $file File Name (relative location such as "image_test.jpg" or full "http://site.com/path/to/image_test.jpg")
  755. * @return String MIMEType - The type of the file passed in the argument
  756. */
  757. public function extractMimeType($file = null) {
  758. if (!is_file($file)) {
  759. return false;
  760. }
  761. /**
  762. * Attempts to retrieve file info from FINFO
  763. * If FINFO functions are not available then try to retrieve MIME type from pre-defined MIMEs
  764. * If MIME type doesn't exist, then try (as a last resort) to use the (deprecated) mime_content_type function
  765. * If all else fails, just return application/octet-stream
  766. */
  767. if (!function_exists("finfo_open")) {
  768. if (function_exists("mime_content_type")) {
  769. $type = mime_content_type($file);
  770. if (!empty($type)) {
  771. return $type;
  772. }
  773. }
  774. $extension = $this->_getExtension($file);
  775. if ($mimeType = $this->getMimeType($extension)) {
  776. return $mimeType;
  777. }
  778. return "application/octet-stream";
  779. }
  780. $finfo = finfo_open(FILEINFO_MIME_TYPE);
  781. $mimeType = finfo_file($finfo, $file);
  782. finfo_close($finfo);
  783. return $mimeType;
  784. }
  785. /**
  786. * Get encoding.
  787. *
  788. * @param string $file
  789. * @param string $default
  790. * @return void
  791. */
  792. public function getEncoding($file = null, $default = 'utf-8') {
  793. if (!function_exists("finfo_open")) {
  794. return $default;
  795. }
  796. $finfo = finfo_open(FILEINFO_MIME_ENCODING);
  797. $encoding = finfo_file($finfo, $file);
  798. finfo_close($finfo);
  799. if ($encoding !== false) {
  800. return $encoding;
  801. }
  802. return $default;
  803. }
  804. /**
  805. * Gets the file extention from a string
  806. *
  807. * @param String $file The full file name
  808. * @return String ext The file extension
  809. */
  810. protected function _getExtension($file = null) {
  811. if ($file !== null) {
  812. $pieces = explode('.', $file);
  813. $ext = strtolower(array_pop($pieces));
  814. return $ext;
  815. }
  816. return false;
  817. }
  818. }