PageRenderTime 59ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/AiP/App/FileServe.php

http://github.com/indeyets/appserver-in-php
PHP | 726 lines | 697 code | 25 blank | 4 comment | 11 complexity | cdec859ea6f4325d7681bc55ef738291 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. <?php
  2. namespace AiP\App;
  3. class FileServe
  4. {
  5. private $path;
  6. public function __construct($path)
  7. {
  8. if (!is_dir($path))
  9. throw new \Exception('"'.$path.'" is not a directory');
  10. $this->path = realpath($path);
  11. }
  12. public function __invoke($ctx)
  13. {
  14. if (isset($ctx['Directory']['path'])) {
  15. $path = $ctx['Directory']['path'];
  16. } else {
  17. $url = $ctx['env']['PATH_INFO'];
  18. if (strpos($url, '..') !== false) {
  19. return array(403, array('Content-Type', 'text/plain'), 'Forbidden');
  20. }
  21. $path = $this->path.$url;
  22. }
  23. // Sanity checks
  24. if (!file_exists($path))
  25. return array(404, array('Content-Type', 'text/plain'), 'File not found');
  26. $path = realpath($path);
  27. if (false === $path) {
  28. // resolving failed. not enough rights for intermediate folder?
  29. return array(404, array('Content-Type', 'text/plain'), 'File not found');
  30. }
  31. if (strpos($path, $this->path) !== 0) {
  32. // gone out of "chroot"?
  33. return array(404, array('Content-Type', 'text/plain'), 'File not found');
  34. }
  35. if (!is_readable($path))
  36. return array(403, array('Content-Type', 'text/plain'), 'Forbidden');
  37. // Only files are served
  38. if (is_dir($path)) {
  39. return array(403, array('Content-Type', 'text/plain'), 'Forbidden');
  40. }
  41. return $this->serve($path);
  42. }
  43. private function serve($path)
  44. {
  45. $stream = fopen($path, 'rb');
  46. $mtime = gmdate('D, d M Y H:i:s', filemtime($path)).' GMT';
  47. $stat = fstat($stream);
  48. $hash = hash_init('sha1');
  49. hash_update_stream($hash, $stream);
  50. hash_update($hash, $mtime);
  51. $etag = hash_final($hash);
  52. fseek($stream, 0, SEEK_SET);
  53. $headers = array(
  54. 'Content-Type', self::getContentType($path),
  55. 'Content-Length', $stat['size'],
  56. 'Last-Modified', $mtime,
  57. 'ETag', $etag,
  58. );
  59. return array(200, $headers, $stream);
  60. }
  61. private static function getContentType($path)
  62. {
  63. static $extensions = null;
  64. if (null === $extensions) {
  65. $extensions = array(
  66. '123' => 'application/vnd.lotus-1-2-3',
  67. '3dml' => 'text/vnd.in3d.3dml',
  68. '3g2' => 'video/3gpp2',
  69. '3gp' => 'video/3gpp',
  70. 'ace' => 'application/x-ace-compressed',
  71. 'acu' => 'application/vnd.acucobol',
  72. 'acutc' => 'application/vnd.acucorp',
  73. 'aep' => 'application/vnd.audiograph',
  74. 'afp' => 'application/vnd.ibm.modcap',
  75. 'ai' => 'application/postscript',
  76. 'aif' => 'audio/x-aiff',
  77. 'aifc' => 'audio/x-aiff',
  78. 'aiff' => 'audio/x-aiff',
  79. 'ami' => 'application/vnd.amiga.ami',
  80. 'apr' => 'application/vnd.lotus-approach',
  81. 'asc' => 'application/pgp-signature',
  82. 'asf' => 'video/x-ms-asf',
  83. 'asm' => 'text/x-asm',
  84. 'aso' => 'application/vnd.accpac.simply.aso',
  85. 'asx' => 'video/x-ms-asf',
  86. 'atc' => 'application/vnd.acucorp',
  87. 'atom' => 'application/atom+xml',
  88. 'atomcat' => 'application/atomcat+xml',
  89. 'atomsvc' => 'application/atomsvc+xml',
  90. 'atx' => 'application/vnd.antix.game-component',
  91. 'au' => 'audio/basic',
  92. 'avi' => 'video/x-msvideo',
  93. 'bat' => 'application/x-msdownload',
  94. 'bcpio' => 'application/x-bcpio',
  95. 'bdm' => 'application/vnd.syncml.dm+wbxml',
  96. 'bh2' => 'application/vnd.fujitsu.oasysprs',
  97. 'bmi' => 'application/vnd.bmi',
  98. 'bmp' => 'image/bmp',
  99. 'box' => 'application/vnd.previewsystems.box',
  100. 'boz' => 'application/x-bzip2',
  101. 'btif' => 'image/prs.btif',
  102. 'bz' => 'application/x-bzip',
  103. 'bz2' => 'application/x-bzip2',
  104. 'c' => 'text/x-c',
  105. 'c4d' => 'application/vnd.clonk.c4group',
  106. 'c4f' => 'application/vnd.clonk.c4group',
  107. 'c4g' => 'application/vnd.clonk.c4group',
  108. 'c4p' => 'application/vnd.clonk.c4group',
  109. 'c4u' => 'application/vnd.clonk.c4group',
  110. 'cab' => 'application/vnd.ms-cab-compressed',
  111. 'cc' => 'text/x-c',
  112. 'ccxml' => 'application/ccxml+xml',
  113. 'cdbcmsg' => 'application/vnd.contact.cmsg',
  114. 'cdf' => 'application/x-netcdf',
  115. 'cdkey' => 'application/vnd.mediastation.cdkey',
  116. 'cdx' => 'chemical/x-cdx',
  117. 'cdxml' => 'application/vnd.chemdraw+xml',
  118. 'cdy' => 'application/vnd.cinderella',
  119. 'cer' => 'application/pkix-cert',
  120. 'cgm' => 'image/cgm',
  121. 'chat' => 'application/x-chat',
  122. 'chm' => 'application/vnd.ms-htmlhelp',
  123. 'chrt' => 'application/vnd.kde.kchart',
  124. 'cif' => 'chemical/x-cif',
  125. 'cii' => 'application/vnd.anser-web-certificate-issue-initiation',
  126. 'cil' => 'application/vnd.ms-artgalry',
  127. 'cla' => 'application/vnd.claymore',
  128. 'clkk' => 'application/vnd.crick.clicker.keyboard',
  129. 'clkp' => 'application/vnd.crick.clicker.palette',
  130. 'clkt' => 'application/vnd.crick.clicker.template',
  131. 'clkw' => 'application/vnd.crick.clicker.wordbank',
  132. 'clkx' => 'application/vnd.crick.clicker',
  133. 'clp' => 'application/x-msclip',
  134. 'cmc' => 'application/vnd.cosmocaller',
  135. 'cmdf' => 'chemical/x-cmdf',
  136. 'cml' => 'chemical/x-cml',
  137. 'cmp' => 'application/vnd.yellowriver-custom-menu',
  138. 'cmx' => 'image/x-cmx',
  139. 'com' => 'application/x-msdownload',
  140. 'conf' => 'text/plain',
  141. 'cpio' => 'application/x-cpio',
  142. 'cpp' => 'text/x-c',
  143. 'cpt' => 'application/mac-compactpro',
  144. 'crd' => 'application/x-mscardfile',
  145. 'crl' => 'application/pkix-crl',
  146. 'crt' => 'application/x-x509-ca-cert',
  147. 'csh' => 'application/x-csh',
  148. 'csml' => 'chemical/x-csml',
  149. 'csp' => 'application/vnd.commonspace',
  150. 'css' => 'text/css',
  151. 'cst' => 'application/vnd.commonspace',
  152. 'csv' => 'text/csv',
  153. 'curl' => 'application/vnd.curl',
  154. 'cww' => 'application/prs.cww',
  155. 'cxx' => 'text/x-c',
  156. 'daf' => 'application/vnd.mobius.daf',
  157. 'davmount' => 'application/davmount+xml',
  158. 'dcr' => 'application/x-director',
  159. 'dd2' => 'application/vnd.oma.dd2+xml',
  160. 'ddd' => 'application/vnd.fujixerox.ddd',
  161. 'def' => 'text/plain',
  162. 'der' => 'application/x-x509-ca-cert',
  163. 'dfac' => 'application/vnd.dreamfactory',
  164. 'dic' => 'text/x-c',
  165. 'dir' => 'application/x-director',
  166. 'dis' => 'application/vnd.mobius.dis',
  167. 'djv' => 'image/vnd.djvu',
  168. 'djvu' => 'image/vnd.djvu',
  169. 'dll' => 'application/x-msdownload',
  170. 'dna' => 'application/vnd.dna',
  171. 'doc' => 'application/msword',
  172. 'dot' => 'application/msword',
  173. 'dp' => 'application/vnd.osgi.dp',
  174. 'dpg' => 'application/vnd.dpgraph',
  175. 'dsc' => 'text/prs.lines.tag',
  176. 'dtd' => 'application/xml-dtd',
  177. 'dvi' => 'application/x-dvi',
  178. 'dwf' => 'model/vnd.dwf',
  179. 'dwg' => 'image/vnd.dwg',
  180. 'dxf' => 'image/vnd.dxf',
  181. 'dxp' => 'application/vnd.spotfire.dxp',
  182. 'dxr' => 'application/x-director',
  183. 'ecelp4800' => 'audio/vnd.nuera.ecelp4800',
  184. 'ecelp7470' => 'audio/vnd.nuera.ecelp7470',
  185. 'ecelp9600' => 'audio/vnd.nuera.ecelp9600',
  186. 'ecma' => 'application/ecmascript',
  187. 'edm' => 'application/vnd.novadigm.edm',
  188. 'edx' => 'application/vnd.novadigm.edx',
  189. 'efif' => 'application/vnd.picsel',
  190. 'ei6' => 'application/vnd.pg.osasli',
  191. 'eml' => 'message/rfc822',
  192. 'eol' => 'audio/vnd.digital-winds',
  193. 'eot' => 'application/vnd.ms-fontobject',
  194. 'eps' => 'application/postscript',
  195. 'es3' => 'application/vnd.eszigno3+xml',
  196. 'esf' => 'application/vnd.epson.esf',
  197. 'et3' => 'application/vnd.eszigno3+xml',
  198. 'etx' => 'text/x-setext',
  199. 'exe' => 'application/x-msdownload',
  200. 'ext' => 'application/vnd.novadigm.ext',
  201. 'ez' => 'application/andrew-inset',
  202. 'ez2' => 'application/vnd.ezpix-album',
  203. 'ez3' => 'application/vnd.ezpix-package',
  204. 'f' => 'text/x-fortran',
  205. 'f77' => 'text/x-fortran',
  206. 'f90' => 'text/x-fortran',
  207. 'fbs' => 'image/vnd.fastbidsheet',
  208. 'fdf' => 'application/vnd.fdf',
  209. 'fe_launch' => 'application/vnd.denovo.fcselayout-link',
  210. 'fg5' => 'application/vnd.fujitsu.oasysgp',
  211. 'fgd' => 'application/x-director',
  212. 'fli' => 'video/x-fli',
  213. 'flo' => 'application/vnd.micrografx.flo',
  214. 'flw' => 'application/vnd.kde.kivio',
  215. 'flx' => 'text/vnd.fmi.flexstor',
  216. 'fly' => 'text/vnd.fly',
  217. 'fm' => 'application/vnd.framemaker',
  218. 'fnc' => 'application/vnd.frogans.fnc',
  219. 'for' => 'text/x-fortran',
  220. 'fpx' => 'image/vnd.fpx',
  221. 'frame' => 'application/vnd.framemaker',
  222. 'fsc' => 'application/vnd.fsc.weblaunch',
  223. 'fst' => 'image/vnd.fst',
  224. 'ftc' => 'application/vnd.fluxtime.clip',
  225. 'fti' => 'application/vnd.anser-web-funds-transfer-initiation',
  226. 'fvt' => 'video/vnd.fvt',
  227. 'fzs' => 'application/vnd.fuzzysheet',
  228. 'g3' => 'image/g3fax',
  229. 'gac' => 'application/vnd.groove-account',
  230. 'gdl' => 'model/vnd.gdl',
  231. 'ghf' => 'application/vnd.groove-help',
  232. 'gif' => 'image/gif',
  233. 'gim' => 'application/vnd.groove-identity-message',
  234. 'gph' => 'application/vnd.flographit',
  235. 'gqf' => 'application/vnd.grafeq',
  236. 'gqs' => 'application/vnd.grafeq',
  237. 'gram' => 'application/srgs',
  238. 'grv' => 'application/vnd.groove-injector',
  239. 'grxml' => 'application/srgs+xml',
  240. 'gtar' => 'application/x-gtar',
  241. 'gtm' => 'application/vnd.groove-tool-message',
  242. 'gtw' => 'model/vnd.gtw',
  243. 'h' => 'text/x-c',
  244. 'h261' => 'video/h261',
  245. 'h263' => 'video/h263',
  246. 'h264' => 'video/h264',
  247. 'hbci' => 'application/vnd.hbci',
  248. 'hdf' => 'application/x-hdf',
  249. 'hh' => 'text/x-c',
  250. 'hlp' => 'application/winhlp',
  251. 'hpgl' => 'application/vnd.hp-hpgl',
  252. 'hpid' => 'application/vnd.hp-hpid',
  253. 'hps' => 'application/vnd.hp-hps',
  254. 'hqx' => 'application/mac-binhex40',
  255. 'htke' => 'application/vnd.kenameaapp',
  256. 'htm' => 'text/html',
  257. 'html' => 'text/html',
  258. 'hvd' => 'application/vnd.yamaha.hv-dic',
  259. 'hvp' => 'application/vnd.yamaha.hv-voice',
  260. 'hvs' => 'application/vnd.yamaha.hv-script',
  261. 'ice' => 'x-conference/x-cooltalk',
  262. 'ico' => 'image/x-icon',
  263. 'ics' => 'text/calendar',
  264. 'ief' => 'image/ief',
  265. 'ifb' => 'text/calendar',
  266. 'ifm' => 'application/vnd.shana.informed.formdata',
  267. 'iges' => 'model/iges',
  268. 'igl' => 'application/vnd.igloader',
  269. 'igs' => 'model/iges',
  270. 'igx' => 'application/vnd.micrografx.igx',
  271. 'iif' => 'application/vnd.shana.informed.interchange',
  272. 'imp' => 'application/vnd.accpac.simply.imp',
  273. 'ims' => 'application/vnd.ms-ims',
  274. 'in' => 'text/plain',
  275. 'ipk' => 'application/vnd.shana.informed.package',
  276. 'irm' => 'application/vnd.ibm.rights-management',
  277. 'irp' => 'application/vnd.irepository.package+xml',
  278. 'itp' => 'application/vnd.shana.informed.formtemplate',
  279. 'ivp' => 'application/vnd.immervision-ivp',
  280. 'ivu' => 'application/vnd.immervision-ivu',
  281. 'jad' => 'text/vnd.sun.j2me.app-descriptor',
  282. 'jam' => 'application/vnd.jam',
  283. 'java' => 'text/x-java-source',
  284. 'jisp' => 'application/vnd.jisp',
  285. 'jlt' => 'application/vnd.hp-jlyt',
  286. 'joda' => 'application/vnd.joost.joda-archive',
  287. 'jpe' => 'image/jpeg',
  288. 'jpeg' => 'image/jpeg',
  289. 'jpg' => 'image/jpeg',
  290. 'jpgm' => 'video/jpm',
  291. 'jpgv' => 'video/jpeg',
  292. 'jpm' => 'video/jpm',
  293. 'js' => 'application/javascript',
  294. 'json' => 'application/json',
  295. 'kar' => 'audio/midi',
  296. 'karbon' => 'application/vnd.kde.karbon',
  297. 'kfo' => 'application/vnd.kde.kformula',
  298. 'kia' => 'application/vnd.kidspiration',
  299. 'kml' => 'application/vnd.google-earth.kml+xml',
  300. 'kmz' => 'application/vnd.google-earth.kmz',
  301. 'kne' => 'application/vnd.kinar',
  302. 'knp' => 'application/vnd.kinar',
  303. 'kon' => 'application/vnd.kde.kontour',
  304. 'kpr' => 'application/vnd.kde.kpresenter',
  305. 'kpt' => 'application/vnd.kde.kpresenter',
  306. 'ksp' => 'application/vnd.kde.kspread',
  307. 'ktr' => 'application/vnd.kahootz',
  308. 'ktz' => 'application/vnd.kahootz',
  309. 'kwd' => 'application/vnd.kde.kword',
  310. 'kwt' => 'application/vnd.kde.kword',
  311. 'latex' => 'application/x-latex',
  312. 'lbd' => 'application/vnd.llamagraphics.life-balance.desktop',
  313. 'lbe' => 'application/vnd.llamagraphics.life-balance.exchange+xml',
  314. 'les' => 'application/vnd.hhe.lesson-player',
  315. 'list' => 'text/plain',
  316. 'list3820' => 'application/vnd.ibm.modcap',
  317. 'listafp' => 'application/vnd.ibm.modcap',
  318. 'log' => 'text/plain',
  319. 'lrm' => 'application/vnd.ms-lrm',
  320. 'ltf' => 'application/vnd.frogans.ltf',
  321. 'lvp' => 'audio/vnd.lucent.voice',
  322. 'lwp' => 'application/vnd.lotus-wordpro',
  323. 'm13' => 'application/x-msmediaview',
  324. 'm14' => 'application/x-msmediaview',
  325. 'm1v' => 'video/mpeg',
  326. 'm2a' => 'audio/mpeg',
  327. 'm2v' => 'video/mpeg',
  328. 'm3a' => 'audio/mpeg',
  329. 'm3u' => 'audio/x-mpegurl',
  330. 'm4u' => 'video/vnd.mpegurl',
  331. 'ma' => 'application/mathematica',
  332. 'mag' => 'application/vnd.ecowin.chart',
  333. 'maker' => 'application/vnd.framemaker',
  334. 'man' => 'text/troff',
  335. 'mathml' => 'application/mathml+xml',
  336. 'mb' => 'application/mathematica',
  337. 'mbk' => 'application/vnd.mobius.mbk',
  338. 'mbox' => 'application/mbox',
  339. 'mc1' => 'application/vnd.medcalcdata',
  340. 'mcd' => 'application/vnd.mcd',
  341. 'mdb' => 'application/x-msaccess',
  342. 'mdi' => 'image/vnd.ms-modi',
  343. 'me' => 'text/troff',
  344. 'mesh' => 'model/mesh',
  345. 'mfm' => 'application/vnd.mfmp',
  346. 'mgz' => 'application/vnd.proteus.magazine',
  347. 'mid' => 'audio/midi',
  348. 'midi' => 'audio/midi',
  349. 'mif' => 'application/vnd.mif',
  350. 'mime' => 'message/rfc822',
  351. 'mj2' => 'video/mj2',
  352. 'mjp2' => 'video/mj2',
  353. 'mlp' => 'application/vnd.dolby.mlp',
  354. 'mmd' => 'application/vnd.chipnuts.karaoke-mmd',
  355. 'mmf' => 'application/vnd.smaf',
  356. 'mmr' => 'image/vnd.fujixerox.edmics-mmr',
  357. 'mny' => 'application/x-msmoney',
  358. 'mov' => 'video/quicktime',
  359. 'movie' => 'video/x-sgi-movie',
  360. 'mp2' => 'audio/mpeg',
  361. 'mp2a' => 'audio/mpeg',
  362. 'mp3' => 'audio/mpeg',
  363. 'mp4' => 'video/mp4',
  364. 'mp4a' => 'audio/mp4',
  365. 'mp4s' => 'application/mp4',
  366. 'mp4v' => 'video/mp4',
  367. 'mpc' => 'application/vnd.mophun.certificate',
  368. 'mpe' => 'video/mpeg',
  369. 'mpeg' => 'video/mpeg',
  370. 'mpg' => 'video/mpeg',
  371. 'mpg4' => 'video/mp4',
  372. 'mpga' => 'audio/mpeg',
  373. 'mpkg' => 'application/vnd.apple.installer+xml',
  374. 'mpm' => 'application/vnd.blueice.multipass',
  375. 'mpn' => 'application/vnd.mophun.application',
  376. 'mpp' => 'application/vnd.ms-project',
  377. 'mpt' => 'application/vnd.ms-project',
  378. 'mpy' => 'application/vnd.ibm.minipay',
  379. 'mqy' => 'application/vnd.mobius.mqy',
  380. 'mrc' => 'application/marc',
  381. 'ms' => 'text/troff',
  382. 'mscml' => 'application/mediaservercontrol+xml',
  383. 'mseq' => 'application/vnd.mseq',
  384. 'msf' => 'application/vnd.epson.msf',
  385. 'msh' => 'model/mesh',
  386. 'msi' => 'application/x-msdownload',
  387. 'msl' => 'application/vnd.mobius.msl',
  388. 'msty' => 'application/vnd.muvee.style',
  389. 'mts' => 'model/vnd.mts',
  390. 'mus' => 'application/vnd.musician',
  391. 'mvb' => 'application/x-msmediaview',
  392. 'mwf' => 'application/vnd.mfer',
  393. 'mxf' => 'application/mxf',
  394. 'mxl' => 'application/vnd.recordare.musicxml',
  395. 'mxml' => 'application/xv+xml',
  396. 'mxs' => 'application/vnd.triscape.mxs',
  397. 'mxu' => 'video/vnd.mpegurl',
  398. 'n-gage' => 'application/vnd.nokia.n-gage.symbian.install',
  399. 'nb' => 'application/mathematica',
  400. 'nc' => 'application/x-netcdf',
  401. 'ngdat' => 'application/vnd.nokia.n-gage.data',
  402. 'nlu' => 'application/vnd.neurolanguage.nlu',
  403. 'nml' => 'application/vnd.enliven',
  404. 'nnd' => 'application/vnd.noblenet-directory',
  405. 'nns' => 'application/vnd.noblenet-sealer',
  406. 'nnw' => 'application/vnd.noblenet-web',
  407. 'npx' => 'image/vnd.net-fpx',
  408. 'nsf' => 'application/vnd.lotus-notes',
  409. 'oa2' => 'application/vnd.fujitsu.oasys2',
  410. 'oa3' => 'application/vnd.fujitsu.oasys3',
  411. 'oas' => 'application/vnd.fujitsu.oasys',
  412. 'obd' => 'application/x-msbinder',
  413. 'oda' => 'application/oda',
  414. 'odc' => 'application/vnd.oasis.opendocument.chart',
  415. 'odf' => 'application/vnd.oasis.opendocument.formula',
  416. 'odg' => 'application/vnd.oasis.opendocument.graphics',
  417. 'odi' => 'application/vnd.oasis.opendocument.image',
  418. 'odp' => 'application/vnd.oasis.opendocument.presentation',
  419. 'ods' => 'application/vnd.oasis.opendocument.spreadsheet',
  420. 'odt' => 'application/vnd.oasis.opendocument.text',
  421. 'ogg' => 'application/ogg',
  422. 'oprc' => 'application/vnd.palm',
  423. 'org' => 'application/vnd.lotus-organizer',
  424. 'otc' => 'application/vnd.oasis.opendocument.chart-template',
  425. 'otf' => 'application/vnd.oasis.opendocument.formula-template',
  426. 'otg' => 'application/vnd.oasis.opendocument.graphics-template',
  427. 'oth' => 'application/vnd.oasis.opendocument.text-web',
  428. 'oti' => 'application/vnd.oasis.opendocument.image-template',
  429. 'otm' => 'application/vnd.oasis.opendocument.text-master',
  430. 'ots' => 'application/vnd.oasis.opendocument.spreadsheet-template',
  431. 'ott' => 'application/vnd.oasis.opendocument.text-template',
  432. 'oxt' => 'application/vnd.openofficeorg.extension',
  433. 'p' => 'text/x-pascal',
  434. 'p10' => 'application/pkcs10',
  435. 'p12' => 'application/x-pkcs12',
  436. 'p7b' => 'application/x-pkcs7-certificates',
  437. 'p7c' => 'application/pkcs7-mime',
  438. 'p7m' => 'application/pkcs7-mime',
  439. 'p7r' => 'application/x-pkcs7-certreqresp',
  440. 'p7s' => 'application/pkcs7-signature',
  441. 'pas' => 'text/x-pascal',
  442. 'pbd' => 'application/vnd.powerbuilder6',
  443. 'pbm' => 'image/x-portable-bitmap',
  444. 'pcl' => 'application/vnd.hp-pcl',
  445. 'pclxl' => 'application/vnd.hp-pclxl',
  446. 'pct' => 'image/x-pict',
  447. 'pcx' => 'image/x-pcx',
  448. 'pdb' => 'chemical/x-pdb',
  449. 'pdf' => 'application/pdf',
  450. 'pfr' => 'application/font-tdpfr',
  451. 'pfx' => 'application/x-pkcs12',
  452. 'pgm' => 'image/x-portable-graymap',
  453. 'pgn' => 'application/x-chess-pgn',
  454. 'pgp' => 'application/pgp-encrypted',
  455. 'pic' => 'image/x-pict',
  456. 'pki' => 'application/pkixcmp',
  457. 'pkipath' => 'application/pkix-pkipath',
  458. 'plb' => 'application/vnd.3gpp.pic-bw-large',
  459. 'plc' => 'application/vnd.mobius.plc',
  460. 'plf' => 'application/vnd.pocketlearn',
  461. 'pls' => 'application/pls+xml',
  462. 'pml' => 'application/vnd.ctc-posml',
  463. 'png' => 'image/png',
  464. 'pnm' => 'image/x-portable-anymap',
  465. 'portpkg' => 'application/vnd.macports.portpkg',
  466. 'pot' => 'application/vnd.ms-powerpoint',
  467. 'ppd' => 'application/vnd.cups-ppd',
  468. 'ppm' => 'image/x-portable-pixmap',
  469. 'pps' => 'application/vnd.ms-powerpoint',
  470. 'ppt' => 'application/vnd.ms-powerpoint',
  471. 'pqa' => 'application/vnd.palm',
  472. 'prc' => 'application/vnd.palm',
  473. 'pre' => 'application/vnd.lotus-freelance',
  474. 'prf' => 'application/pics-rules',
  475. 'ps' => 'application/postscript',
  476. 'psb' => 'application/vnd.3gpp.pic-bw-small',
  477. 'psd' => 'image/vnd.adobe.photoshop',
  478. 'ptid' => 'application/vnd.pvi.ptid1',
  479. 'pub' => 'application/x-mspublisher',
  480. 'pvb' => 'application/vnd.3gpp.pic-bw-var',
  481. 'pwn' => 'application/vnd.3m.post-it-notes',
  482. 'qam' => 'application/vnd.epson.quickanime',
  483. 'qbo' => 'application/vnd.intu.qbo',
  484. 'qfx' => 'application/vnd.intu.qfx',
  485. 'qps' => 'application/vnd.publishare-delta-tree',
  486. 'qt' => 'video/quicktime',
  487. 'qwd' => 'application/vnd.quark.quarkxpress',
  488. 'qwt' => 'application/vnd.quark.quarkxpress',
  489. 'qxb' => 'application/vnd.quark.quarkxpress',
  490. 'qxd' => 'application/vnd.quark.quarkxpress',
  491. 'qxl' => 'application/vnd.quark.quarkxpress',
  492. 'qxt' => 'application/vnd.quark.quarkxpress',
  493. 'ra' => 'audio/x-pn-realaudio',
  494. 'ram' => 'audio/x-pn-realaudio',
  495. 'rar' => 'application/x-rar-compressed',
  496. 'ras' => 'image/x-cmu-raster',
  497. 'rcprofile' => 'application/vnd.ipunplugged.rcprofile',
  498. 'rdf' => 'application/rdf+xml',
  499. 'rdz' => 'application/vnd.data-vision.rdz',
  500. 'rep' => 'application/vnd.businessobjects',
  501. 'rgb' => 'image/x-rgb',
  502. 'rif' => 'application/reginfo+xml',
  503. 'rl' => 'application/resource-lists+xml',
  504. 'rlc' => 'image/vnd.fujixerox.edmics-rlc',
  505. 'rm' => 'application/vnd.rn-realmedia',
  506. 'rmi' => 'audio/midi',
  507. 'rmp' => 'audio/x-pn-realaudio-plugin',
  508. 'rms' => 'application/vnd.jcp.javame.midlet-rms',
  509. 'rnc' => 'application/relax-ng-compact-syntax',
  510. 'roff' => 'text/troff',
  511. 'rpss' => 'application/vnd.nokia.radio-presets',
  512. 'rpst' => 'application/vnd.nokia.radio-preset',
  513. 'rq' => 'application/sparql-query',
  514. 'rs' => 'application/rls-services+xml',
  515. 'rsd' => 'application/rsd+xml',
  516. 'rss' => 'application/rss+xml',
  517. 'rtf' => 'application/rtf',
  518. 'rtx' => 'text/richtext',
  519. 's' => 'text/x-asm',
  520. 'saf' => 'application/vnd.yamaha.smaf-audio',
  521. 'sbml' => 'application/sbml+xml',
  522. 'sc' => 'application/vnd.ibm.secure-container',
  523. 'scd' => 'application/x-msschedule',
  524. 'scm' => 'application/vnd.lotus-screencam',
  525. 'scq' => 'application/scvp-cv-request',
  526. 'scs' => 'application/scvp-cv-response',
  527. 'sdkd' => 'application/vnd.solent.sdkm+xml',
  528. 'sdkm' => 'application/vnd.solent.sdkm+xml',
  529. 'sdp' => 'application/sdp',
  530. 'see' => 'application/vnd.seemail',
  531. 'sema' => 'application/vnd.sema',
  532. 'semd' => 'application/vnd.semd',
  533. 'semf' => 'application/vnd.semf',
  534. 'setpay' => 'application/set-payment-initiation',
  535. 'setreg' => 'application/set-registration-initiation',
  536. 'sfs' => 'application/vnd.spotfire.sfs',
  537. 'sgm' => 'text/sgml',
  538. 'sgml' => 'text/sgml',
  539. 'sh' => 'application/x-sh',
  540. 'shar' => 'application/x-shar',
  541. 'shf' => 'application/shf+xml',
  542. 'sig' => 'application/pgp-signature',
  543. 'silo' => 'model/mesh',
  544. 'sit' => 'application/x-stuffit',
  545. 'sitx' => 'application/x-stuffitx',
  546. 'skd' => 'application/vnd.koan',
  547. 'skm' => 'application/vnd.koan',
  548. 'skp' => 'application/vnd.koan',
  549. 'skt' => 'application/vnd.koan',
  550. 'slt' => 'application/vnd.epson.salt',
  551. 'smi' => 'application/smil+xml',
  552. 'smil' => 'application/smil+xml',
  553. 'snd' => 'audio/basic',
  554. 'spc' => 'application/x-pkcs7-certificates',
  555. 'spf' => 'application/vnd.yamaha.smaf-phrase',
  556. 'spl' => 'application/x-futuresplash',
  557. 'spot' => 'text/vnd.in3d.spot',
  558. 'spp' => 'application/scvp-vp-response',
  559. 'spq' => 'application/scvp-vp-request',
  560. 'src' => 'application/x-wais-source',
  561. 'srx' => 'application/sparql-results+xml',
  562. 'ssf' => 'application/vnd.epson.ssf',
  563. 'ssml' => 'application/ssml+xml',
  564. 'stf' => 'application/vnd.wt.stf',
  565. 'stk' => 'application/hyperstudio',
  566. 'str' => 'application/vnd.pg.format',
  567. 'sus' => 'application/vnd.sus-calendar',
  568. 'susp' => 'application/vnd.sus-calendar',
  569. 'sv4cpio' => 'application/x-sv4cpio',
  570. 'sv4crc' => 'application/x-sv4crc',
  571. 'svd' => 'application/vnd.svd',
  572. 'svg' => 'image/svg+xml',
  573. 'svgz' => 'image/svg+xml',
  574. 'swf' => 'application/x-shockwave-flash',
  575. 't' => 'text/troff',
  576. 'tao' => 'application/vnd.tao.intent-module-archive',
  577. 'tar' => 'application/x-tar',
  578. 'tcap' => 'application/vnd.3gpp2.tcap',
  579. 'tcl' => 'application/x-tcl',
  580. 'tex' => 'application/x-tex',
  581. 'texi' => 'application/x-texinfo',
  582. 'texinfo' => 'application/x-texinfo',
  583. 'text' => 'text/plain',
  584. 'tif' => 'image/tiff',
  585. 'tiff' => 'image/tiff',
  586. 'tmo' => 'application/vnd.tmobile-livetv',
  587. 'torrent' => 'application/x-bittorrent',
  588. 'tpl' => 'application/vnd.groove-tool-template',
  589. 'tpt' => 'application/vnd.trid.tpt',
  590. 'tr' => 'text/troff',
  591. 'tra' => 'application/vnd.trueapp',
  592. 'trm' => 'application/x-msterminal',
  593. 'tsv' => 'text/tab-separated-values',
  594. 'twd' => 'application/vnd.simtech-mindmapper',
  595. 'twds' => 'application/vnd.simtech-mindmapper',
  596. 'txd' => 'application/vnd.genomatix.tuxedo',
  597. 'txf' => 'application/vnd.mobius.txf',
  598. 'txt' => 'text/plain',
  599. 'ufd' => 'application/vnd.ufdl',
  600. 'ufdl' => 'application/vnd.ufdl',
  601. 'umj' => 'application/vnd.umajin',
  602. 'unityweb' => 'application/vnd.unity',
  603. 'uoml' => 'application/vnd.uoml+xml',
  604. 'uri' => 'text/uri-list',
  605. 'uris' => 'text/uri-list',
  606. 'urls' => 'text/uri-list',
  607. 'ustar' => 'application/x-ustar',
  608. 'utz' => 'application/vnd.uiq.theme',
  609. 'uu' => 'text/x-uuencode',
  610. 'vcd' => 'application/x-cdlink',
  611. 'vcf' => 'text/x-vcard',
  612. 'vcg' => 'application/vnd.groove-vcard',
  613. 'vcs' => 'text/x-vcalendar',
  614. 'vcx' => 'application/vnd.vcx',
  615. 'vis' => 'application/vnd.visionary',
  616. 'viv' => 'video/vnd.vivo',
  617. 'vrml' => 'model/vrml',
  618. 'vsd' => 'application/vnd.visio',
  619. 'vsf' => 'application/vnd.vsf',
  620. 'vss' => 'application/vnd.visio',
  621. 'vst' => 'application/vnd.visio',
  622. 'vsw' => 'application/vnd.visio',
  623. 'vtu' => 'model/vnd.vtu',
  624. 'vxml' => 'application/voicexml+xml',
  625. 'wav' => 'audio/x-wav',
  626. 'wax' => 'audio/x-ms-wax',
  627. 'wbmp' => 'image/vnd.wap.wbmp',
  628. 'wbs' => 'application/vnd.criticaltools.wbs+xml',
  629. 'wbxml' => 'application/vnd.wap.wbxml',
  630. 'wcm' => 'application/vnd.ms-works',
  631. 'wdb' => 'application/vnd.ms-works',
  632. 'wks' => 'application/vnd.ms-works',
  633. 'wm' => 'video/x-ms-wm',
  634. 'wma' => 'audio/x-ms-wma',
  635. 'wmd' => 'application/x-ms-wmd',
  636. 'wmf' => 'application/x-msmetafile',
  637. 'wml' => 'text/vnd.wap.wml',
  638. 'wmlc' => 'application/vnd.wap.wmlc',
  639. 'wmls' => 'text/vnd.wap.wmlscript',
  640. 'wmlsc' => 'application/vnd.wap.wmlscriptc',
  641. 'wmv' => 'video/x-ms-wmv',
  642. 'wmx' => 'video/x-ms-wmx',
  643. 'wmz' => 'application/x-ms-wmz',
  644. 'wpd' => 'application/vnd.wordperfect',
  645. 'wpl' => 'application/vnd.ms-wpl',
  646. 'wps' => 'application/vnd.ms-works',
  647. 'wqd' => 'application/vnd.wqd',
  648. 'wri' => 'application/x-mswrite',
  649. 'wrl' => 'model/vrml',
  650. 'wsdl' => 'application/wsdl+xml',
  651. 'wspolicy' => 'application/wspolicy+xml',
  652. 'wtb' => 'application/vnd.webturbo',
  653. 'wvx' => 'video/x-ms-wvx',
  654. 'x3d' => 'application/vnd.hzn-3d-crossword',
  655. 'xar' => 'application/vnd.xara',
  656. 'xbd' => 'application/vnd.fujixerox.docuworks.binder',
  657. 'xbm' => 'image/x-xbitmap',
  658. 'xdm' => 'application/vnd.syncml.dm+xml',
  659. 'xdp' => 'application/vnd.adobe.xdp+xml',
  660. 'xdw' => 'application/vnd.fujixerox.docuworks',
  661. 'xenc' => 'application/xenc+xml',
  662. 'xfdf' => 'application/vnd.adobe.xfdf',
  663. 'xfdl' => 'application/vnd.xfdl',
  664. 'xht' => 'application/xhtml+xml',
  665. 'xhtml' => 'application/xhtml+xml',
  666. 'xhvml' => 'application/xv+xml',
  667. 'xif' => 'image/vnd.xiff',
  668. 'xla' => 'application/vnd.ms-excel',
  669. 'xlc' => 'application/vnd.ms-excel',
  670. 'xlm' => 'application/vnd.ms-excel',
  671. 'xls' => 'application/vnd.ms-excel',
  672. 'xlt' => 'application/vnd.ms-excel',
  673. 'xlw' => 'application/vnd.ms-excel',
  674. 'xml' => 'application/xml',
  675. 'xo' => 'application/vnd.olpc-sugar',
  676. 'xop' => 'application/xop+xml',
  677. 'xpm' => 'image/x-xpixmap',
  678. 'xpr' => 'application/vnd.is-xpr',
  679. 'xps' => 'application/vnd.ms-xpsdocument',
  680. 'xpw' => 'application/vnd.intercon.formnet',
  681. 'xpx' => 'application/vnd.intercon.formnet',
  682. 'xsl' => 'application/xml',
  683. 'xslt' => 'application/xslt+xml',
  684. 'xsm' => 'application/vnd.syncml+xml',
  685. 'xspf' => 'application/xspf+xml',
  686. 'xul' => 'application/vnd.mozilla.xul+xml',
  687. 'xvm' => 'application/xv+xml',
  688. 'xvml' => 'application/xv+xml',
  689. 'xwd' => 'image/x-xwindowdump',
  690. 'xyz' => 'chemical/x-xyz',
  691. 'zaz' => 'application/vnd.zzazz.deck+xml',
  692. 'zip' => 'application/zip',
  693. 'zmm' => 'application/vnd.handheld-entertainment+xml',
  694. );
  695. }
  696. $extension = pathinfo($path, PATHINFO_EXTENSION);
  697. if (isset($extensions[$extension]))
  698. return $extensions[$extension];
  699. return 'text/plain';
  700. }
  701. }