/administrator/components/com_zoo/framework/helpers/filesystem.php

https://gitlab.com/vnsoftdev/amms · PHP · 757 lines · 617 code · 47 blank · 93 comment · 31 complexity · cadbc3eb8ddbec991053cc2fc25cda38 MD5 · raw file

  1. <?php
  2. /**
  3. * @package com_zoo
  4. * @author YOOtheme http://www.yootheme.com
  5. * @copyright Copyright (C) YOOtheme GmbH
  6. * @license http://www.gnu.org/licenses/gpl.html GNU/GPL
  7. */
  8. /**
  9. * Filesystem Helper. Deals with files and directories
  10. *
  11. * @package Framework.Helpers
  12. */
  13. class FilesystemHelper extends AppHelper {
  14. /**
  15. * Get a file size with a suffix (B, KB, MB, etc)
  16. *
  17. * @param int $bytes The number of bytes
  18. *
  19. * @return string The file size with a suffix
  20. *
  21. * @since 1.0.0
  22. */
  23. public function formatFilesize($bytes) {
  24. $exp = 0;
  25. $value = 0;
  26. $symbol = array('B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB');
  27. if ($bytes > 0) {
  28. $exp = floor( log($bytes)/log(1024));
  29. $value = ($bytes/pow(1024,floor($exp)));
  30. }
  31. return sprintf('%.2f '.$symbol[$exp], $value);
  32. }
  33. /**
  34. * Output a file to the browser
  35. *
  36. * @param string $file The file to output
  37. *
  38. * @since 1.0.0
  39. */
  40. public function output($file) {
  41. @error_reporting(E_ERROR);
  42. $name = basename($file);
  43. $type = $this->getContentType($name);
  44. $size = @filesize($file);
  45. $mod = date('r', filemtime($file));
  46. while (@ob_end_clean());
  47. // required for IE, otherwise Content-disposition is ignored
  48. if (ini_get('zlib.output_compression')) {
  49. ini_set('zlib.output_compression', 'Off');
  50. }
  51. // set header
  52. header("Pragma: public");
  53. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  54. header("Expires: 0");
  55. header("Content-Transfer-Encoding: binary");
  56. header('Content-Type: '.$type);
  57. header('Content-Disposition: attachment;'
  58. .' filename="'.$name.'";'
  59. .' modification-date="'.$mod.'";'
  60. .' size='.$size.';');
  61. header("Content-Length: ".$size);
  62. // set_time_limit doesn't work in safe mode
  63. if (!ini_get('safe_mode')) {
  64. @set_time_limit(0);
  65. }
  66. // output file
  67. $handle = fopen($file, 'rb');
  68. fpassthru($handle);
  69. fclose($handle);
  70. }
  71. /**
  72. * Get a list of directories from the given directory
  73. *
  74. * @param string $path The path of the directory
  75. * @param string $prefix A prefix to prepend
  76. * @param string $filter A regex used to filter directories
  77. * @param boolean $recursive If the search should be recursive (default: true)
  78. *
  79. * @return array The list of subdirectories
  80. *
  81. * @since 1.0.0
  82. */
  83. public function readDirectory($path, $prefix = '', $filter = false, $recursive = true) {
  84. $dirs = array();
  85. $ignore = array('.', '..', '.DS_Store', '.svn', '.git', '.gitignore', '.gitmodules', 'cgi-bin');
  86. if (is_readable($path) && is_dir($path) && $handle = @opendir($path)) {
  87. while (false !== ($file = readdir($handle))) {
  88. // continue if ignore match
  89. if (in_array($file, $ignore)) {
  90. continue;
  91. }
  92. if (is_dir($path.'/'.$file)) {
  93. // continue if not recursive
  94. if (!$recursive) {
  95. continue;
  96. }
  97. // continue if no regex filter match
  98. if ($filter && !preg_match($filter, $file)) {
  99. continue;
  100. }
  101. // read subdirectory
  102. $dirs[] = $prefix.$file;
  103. $dirs = array_merge($dirs, $this->readDirectory($path.'/'.$file, $prefix.$file.'/', $filter, $recursive));
  104. }
  105. }
  106. closedir($handle);
  107. }
  108. return $dirs;
  109. }
  110. /**
  111. * Get a list of files in the given directory
  112. *
  113. * @param string $path The path to search in
  114. * @param string $prefix A prefix to prepend
  115. * @param string $filter A regex to filter the files
  116. * @param boolean $recursive If the search should be recursive (default: true)
  117. *
  118. * @return array The list of files
  119. *
  120. * @since 1.0.0
  121. */
  122. public function readDirectoryFiles($path, $prefix = '', $filter = false, $recursive = true) {
  123. $files = array();
  124. $ignore = array('.', '..', '.DS_Store', '.svn', '.git', '.gitignore', '.gitmodules', 'cgi-bin');
  125. if (is_readable($path) && is_dir($path) && $handle = @opendir($path)) {
  126. while (false !== ($file = readdir($handle))) {
  127. // continue if ignore match
  128. if (in_array($file, $ignore)) {
  129. continue;
  130. }
  131. if (is_dir($path.'/'.$file)) {
  132. // continue if not recursive
  133. if (!$recursive) {
  134. continue;
  135. }
  136. // read subdirectory
  137. $files = array_merge($files, $this->readDirectoryFiles($path.'/'.$file, $prefix.$file.'/', $filter, $recursive));
  138. } else {
  139. // continue if no regex filter match
  140. if ($filter && !preg_match($filter, $file)) {
  141. continue;
  142. }
  143. $files[] = $prefix.$file;
  144. }
  145. }
  146. closedir($handle);
  147. }
  148. return $files;
  149. }
  150. /**
  151. * Get the file extension
  152. *
  153. * @param string $filename The file name
  154. *
  155. * @return string The file extension
  156. *
  157. * @since 1.0.0
  158. */
  159. public function getExtension($filename) {
  160. $mimes = $this->getMimeMapping();
  161. $file = pathinfo($filename);
  162. $ext = isset($file['extension']) ? $file['extension'] : null;
  163. if ($ext) {
  164. // check extensions content type (with dot, like tar.gz)
  165. if (($pos = strrpos($file['filename'], '.')) !== false) {
  166. $ext2 = strtolower(substr($file['filename'], $pos + 1).'.'.$ext);
  167. if (array_key_exists($ext2, $mimes)) {
  168. return $ext2;
  169. }
  170. }
  171. // check extensions content type
  172. $ext = strtolower($ext);
  173. if (array_key_exists(strtolower($ext), $mimes)) {
  174. return $ext;
  175. }
  176. }
  177. return null;
  178. }
  179. /**
  180. * Get the content type of a file
  181. *
  182. * @param string $filename The file name
  183. *
  184. * @return string The content type
  185. *
  186. * @since 1.0.0
  187. */
  188. public function getContentType($filename) {
  189. $mimes = $this->getMimeMapping();
  190. $file = pathinfo($filename);
  191. $ext = $file['extension'];
  192. if ($ext) {
  193. // check extensions content type (with dot, like tar.gz)
  194. if (($pos = strrpos($file['filename'], '.')) !== false) {
  195. $ext2 = strtolower(substr($file['filename'], $pos + 1).'.'.$ext);
  196. if (array_key_exists($ext2, $mimes)) {
  197. return array_shift($mimes[$ext2]);
  198. }
  199. }
  200. // check extensions content type
  201. $ext = strtolower($ext);
  202. if (array_key_exists(strtolower($ext), $mimes)) {
  203. return array_shift($mimes[$ext]);
  204. }
  205. }
  206. return 'application/octet-stream';
  207. }
  208. /**
  209. * Get the mapping from extension to mime type
  210. *
  211. * @return array The associative array of extension => mime type mapping
  212. *
  213. * @since 1.0.0
  214. */
  215. public static function getMimeMapping() {
  216. $mimes = array();
  217. $mimes['3ds'][] = 'image/x-3ds';
  218. $mimes['BLEND'][] = 'application/x-blender';
  219. $mimes['C'][] = 'text/x-c++src';
  220. $mimes['CSSL'][] = 'text/css';
  221. $mimes['NSV'][] = 'video/x-nsv';
  222. $mimes['XM'][] = 'audio/x-mod';
  223. $mimes['Z'][] = 'application/x-compress';
  224. $mimes['a'][] = 'application/x-archive';
  225. $mimes['abw'][] = 'application/x-abiword';
  226. $mimes['abw.gz'][] = 'application/x-abiword';
  227. $mimes['ac3'][] = 'audio/ac3';
  228. $mimes['adb'][] = 'text/x-adasrc';
  229. $mimes['ads'][] = 'text/x-adasrc';
  230. $mimes['afm'][] = 'application/x-font-afm';
  231. $mimes['ag'][] = 'image/x-applix-graphics';
  232. $mimes['ai'][] = 'application/illustrator';
  233. $mimes['aif'][] = 'audio/x-aiff';
  234. $mimes['aifc'][] = 'audio/x-aiff';
  235. $mimes['aiff'][] = 'audio/x-aiff';
  236. $mimes['al'][] = 'application/x-perl';
  237. $mimes['arj'][] = 'application/x-arj';
  238. $mimes['as'][] = 'application/x-applix-spreadsheet';
  239. $mimes['asc'][] = 'text/plain';
  240. $mimes['asf'][] = 'video/x-ms-asf';
  241. $mimes['asp'][] = 'application/x-asp';
  242. $mimes['asx'][] = 'video/x-ms-asf';
  243. $mimes['au'][] = 'audio/basic';
  244. $mimes['avi'][] = 'video/x-msvideo';
  245. $mimes['avi'][] = 'video/avi'; // IE
  246. $mimes['aw'][] = 'application/x-applix-word';
  247. $mimes['bak'][] = 'application/x-trash';
  248. $mimes['bcpio'][] = 'application/x-bcpio';
  249. $mimes['bdf'][] = 'application/x-font-bdf';
  250. $mimes['bib'][] = 'text/x-bibtex';
  251. $mimes['bin'][] = 'application/octet-stream';
  252. $mimes['blend'][] = 'application/x-blender';
  253. $mimes['blender'][] = 'application/x-blender';
  254. $mimes['bmp'][] = 'image/bmp';
  255. $mimes['bz'][] = 'application/x-bzip';
  256. $mimes['bz2'][] = 'application/x-bzip';
  257. $mimes['c'][] = 'text/x-csrc';
  258. $mimes['c++'][] = 'text/x-c++src';
  259. $mimes['cc'][] = 'text/x-c++src';
  260. $mimes['cdf'][] = 'application/x-netcdf';
  261. $mimes['cdr'][] = 'application/vnd.corel-draw';
  262. $mimes['cer'][] = 'application/x-x509-ca-cert';
  263. $mimes['cert'][] = 'application/x-x509-ca-cert';
  264. $mimes['cgi'][] = 'application/x-cgi';
  265. $mimes['cgm'][] = 'image/cgm';
  266. $mimes['chrt'][] = 'application/x-kchart';
  267. $mimes['class'][] = 'application/x-java';
  268. $mimes['cls'][] = 'text/x-tex';
  269. $mimes['cpio'][] = 'application/x-cpio';
  270. $mimes['cpio.gz'][] = 'application/x-cpio-compressed';
  271. $mimes['cpp'][] = 'text/x-c++src';
  272. $mimes['cpt'][] = 'application/mac-compactpro';
  273. $mimes['crt'][] = 'application/x-x509-ca-cert';
  274. $mimes['cs'][] = 'text/x-csharp';
  275. $mimes['csh'][] = 'application/x-shellscript';
  276. $mimes['css'][] = 'text/css';
  277. $mimes['csv'][] = 'text/x-comma-separated-values';
  278. $mimes['cur'][] = 'image/x-win-bitmap';
  279. $mimes['cxx'][] = 'text/x-c++src';
  280. $mimes['dat'][] = 'video/mpeg';
  281. $mimes['dbf'][] = 'application/x-dbase';
  282. $mimes['dc'][] = 'application/x-dc-rom';
  283. $mimes['dcl'][] = 'text/x-dcl';
  284. $mimes['dcm'][] = 'image/x-dcm';
  285. $mimes['dcr'][] = 'application/x-director';
  286. $mimes['dd2'][] = 'application/vnd.oma.dd2+xml';
  287. $mimes['deb'][] = 'application/x-deb';
  288. $mimes['der'][] = 'application/x-x509-ca-cert';
  289. $mimes['desktop'][] = 'application/x-desktop';
  290. $mimes['dia'][] = 'application/x-dia-diagram';
  291. $mimes['diff'][] = 'text/x-patch';
  292. $mimes['dir'][] = 'application/x-director';
  293. $mimes['djv'][] = 'image/vnd.djvu';
  294. $mimes['djvu'][] = 'image/vnd.djvu';
  295. $mimes['dll'][] = 'application/octet-stream';
  296. $mimes['dms'][] = 'application/octet-stream';
  297. $mimes['doc'][] = 'application/msword';
  298. $mimes['dsl'][] = 'text/x-dsl';
  299. $mimes['dtd'][] = 'text/x-dtd';
  300. $mimes['dvi'][] = 'application/x-dvi';
  301. $mimes['dwg'][] = 'image/vnd.dwg';
  302. $mimes['dxf'][] = 'image/vnd.dxf';
  303. $mimes['dxr'][] = 'application/x-director';
  304. $mimes['egon'][] = 'application/x-egon';
  305. $mimes['el'][] = 'text/x-emacs-lisp';
  306. $mimes['eps'][] = 'image/x-eps';
  307. $mimes['epsf'][] = 'image/x-eps';
  308. $mimes['epsi'][] = 'image/x-eps';
  309. $mimes['etheme'][] = 'application/x-e-theme';
  310. $mimes['etx'][] = 'text/x-setext';
  311. $mimes['exe'][] = 'application/x-executable';
  312. $mimes['exe'][] = 'application/x-msdownload'; // IE
  313. $mimes['ez'][] = 'application/andrew-inset';
  314. $mimes['f'][] = 'text/x-fortran';
  315. $mimes['fig'][] = 'image/x-xfig';
  316. $mimes['fits'][] = 'image/x-fits';
  317. $mimes['flac'][] = 'audio/x-flac';
  318. $mimes['flc'][] = 'video/x-flic';
  319. $mimes['fli'][] = 'video/x-flic';
  320. $mimes['flv'][] = 'video/x-flv';
  321. $mimes['flw'][] = 'application/x-kivio';
  322. $mimes['fo'][] = 'text/x-xslfo';
  323. $mimes['g3'][] = 'image/fax-g3';
  324. $mimes['gb'][] = 'application/x-gameboy-rom';
  325. $mimes['gcrd'][] = 'text/x-vcard';
  326. $mimes['gen'][] = 'application/x-genesis-rom';
  327. $mimes['gg'][] = 'application/x-sms-rom';
  328. $mimes['gif'][] = 'image/gif';
  329. $mimes['glade'][] = 'application/x-glade';
  330. $mimes['gmo'][] = 'application/x-gettext-translation';
  331. $mimes['gnc'][] = 'application/x-gnucash';
  332. $mimes['gnucash'][] = 'application/x-gnucash';
  333. $mimes['gnumeric'][] = 'application/x-gnumeric';
  334. $mimes['gra'][] = 'application/x-graphite';
  335. $mimes['gsf'][] = 'application/x-font-type1';
  336. $mimes['gtar'][] = 'application/x-gtar';
  337. $mimes['gz'][] = 'application/gzip';
  338. $mimes['gz'][] = 'application/x-gzip';
  339. $mimes['gz'][] = 'application/x-gzip-compressed'; // IE
  340. $mimes['h'][] = 'text/x-chdr';
  341. $mimes['h++'][] = 'text/x-chdr';
  342. $mimes['hdf'][] = 'application/x-hdf';
  343. $mimes['hh'][] = 'text/x-c++hdr';
  344. $mimes['hp'][] = 'text/x-chdr';
  345. $mimes['hpgl'][] = 'application/vnd.hp-hpgl';
  346. $mimes['hqx'][] = 'application/mac-binhex40';
  347. $mimes['hs'][] = 'text/x-haskell';
  348. $mimes['htm'][] = 'text/html';
  349. $mimes['html'][] = 'text/html';
  350. $mimes['icb'][] = 'image/x-icb';
  351. $mimes['ice'][] = 'x-conference/x-cooltalk';
  352. $mimes['ico'][] = 'image/x-ico';
  353. $mimes['ics'][] = 'text/calendar';
  354. $mimes['idl'][] = 'text/x-idl';
  355. $mimes['ief'][] = 'image/ief';
  356. $mimes['ifb'][] = 'text/calendar';
  357. $mimes['iff'][] = 'image/x-iff';
  358. $mimes['iges'][] = 'model/iges';
  359. $mimes['igs'][] = 'model/iges';
  360. $mimes['igs'][] = 'application/iges';
  361. $mimes['ilbm'][] = 'image/x-ilbm';
  362. $mimes['iso'][] = 'application/x-cd-image';
  363. $mimes['it'][] = 'audio/x-it';
  364. $mimes['jar'][] = 'application/x-jar';
  365. $mimes['java'][] = 'text/x-java';
  366. $mimes['jng'][] = 'image/x-jng';
  367. $mimes['jp2'][] = 'image/jpeg2000';
  368. $mimes['jpg'][] = 'image/jpeg';
  369. $mimes['jpg'][] = 'image/pjpeg'; // IE
  370. $mimes['jpe'][] = 'image/jpeg';
  371. $mimes['jpeg'][] = 'image/jpeg';
  372. $mimes['jpeg'][] = 'image/pjpeg'; // IE
  373. $mimes['jpr'][] = 'application/x-jbuilder-project';
  374. $mimes['jpx'][] = 'application/x-jbuilder-project';
  375. $mimes['js'][] = 'application/x-javascript';
  376. $mimes['kar'][] = 'audio/midi';
  377. $mimes['karbon'][] = 'application/x-karbon';
  378. $mimes['kdelnk'][] = 'application/x-desktop';
  379. $mimes['kfo'][] = 'application/x-kformula';
  380. $mimes['kil'][] = 'application/x-killustrator';
  381. $mimes['kon'][] = 'application/x-kontour';
  382. $mimes['kpm'][] = 'application/x-kpovmodeler';
  383. $mimes['kpr'][] = 'application/x-kpresenter';
  384. $mimes['kpt'][] = 'application/x-kpresenter';
  385. $mimes['kra'][] = 'application/x-krita';
  386. $mimes['ksp'][] = 'application/x-kspread';
  387. $mimes['kud'][] = 'application/x-kugar';
  388. $mimes['kwd'][] = 'application/x-kword';
  389. $mimes['kwt'][] = 'application/x-kword';
  390. $mimes['la'][] = 'application/x-shared-library-la';
  391. $mimes['latex'][] = 'application/x-latex';
  392. $mimes['lha'][] = 'application/x-lha';
  393. $mimes['lhs'][] = 'text/x-literate-haskell';
  394. $mimes['lhz'][] = 'application/x-lhz';
  395. $mimes['log'][] = 'text/x-log';
  396. $mimes['ltx'][] = 'text/x-tex';
  397. $mimes['lwo'][] = 'image/x-lwo';
  398. $mimes['lwob'][] = 'image/x-lwo';
  399. $mimes['lws'][] = 'image/x-lws';
  400. $mimes['lyx'][] = 'application/x-lyx';
  401. $mimes['lzh'][] = 'application/x-lha';
  402. $mimes['lzo'][] = 'application/x-lzop';
  403. $mimes['m'][] = 'text/x-objcsrc';
  404. $mimes['m15'][] = 'audio/x-mod';
  405. $mimes['m3u'][] = 'audio/x-mpegurl';
  406. $mimes['m4v'][] = 'video/x-m4v';
  407. $mimes['man'][] = 'application/x-troff-man';
  408. $mimes['md'][] = 'application/x-genesis-rom';
  409. $mimes['me'][] = 'text/x-troff-me';
  410. $mimes['mesh'][] = 'model/mesh';
  411. $mimes['mgp'][] = 'application/x-magicpoint';
  412. $mimes['mid'][] = 'audio/midi';
  413. $mimes['mid'][] = 'audio/mid'; // IE
  414. $mimes['midi'][] = 'audio/midi';
  415. $mimes['mif'][] = 'application/x-mif';
  416. $mimes['mkv'][] = 'application/x-matroska';
  417. $mimes['mm'][] = 'text/x-troff-mm';
  418. $mimes['mml'][] = 'text/mathml';
  419. $mimes['mng'][] = 'video/x-mng';
  420. $mimes['moc'][] = 'text/x-moc';
  421. $mimes['mod'][] = 'audio/x-mod';
  422. $mimes['moov'][] = 'video/quicktime';
  423. $mimes['mov'][] = 'video/quicktime';
  424. $mimes['movie'][] = 'video/x-sgi-movie';
  425. $mimes['mp2'][] = 'video/mpeg';
  426. $mimes['mp3'][] = 'audio/mpeg';
  427. $mimes['mp4'][] = 'video/mp4';
  428. $mimes['mpe'][] = 'video/mpeg';
  429. $mimes['mpeg'][] = 'video/mpeg';
  430. $mimes['mpg'][] = 'video/mpeg';
  431. $mimes['mpga'][] = 'audio/mpeg';
  432. $mimes['ms'][] = 'text/x-troff-ms';
  433. $mimes['msh'][] = 'model/mesh';
  434. $mimes['msod'][] = 'image/x-msod';
  435. $mimes['msx'][] = 'application/x-msx-rom';
  436. $mimes['mtm'][] = 'audio/x-mod';
  437. $mimes['mxu'][] = 'video/vnd.mpegurl';
  438. $mimes['n64'][] = 'application/x-n64-rom';
  439. $mimes['nc'][] = 'application/x-netcdf';
  440. $mimes['nes'][] = 'application/x-nes-rom';
  441. $mimes['nsv'][] = 'video/x-nsv';
  442. $mimes['o'][] = 'application/x-object';
  443. $mimes['obj'][] = 'application/x-tgif';
  444. $mimes['oda'][] = 'application/oda';
  445. $mimes['odb'][] = 'application/vnd.oasis.opendocument.database';
  446. $mimes['odc'][] = 'application/vnd.oasis.opendocument.chart';
  447. $mimes['odf'][] = 'application/vnd.oasis.opendocument.formula';
  448. $mimes['odg'][] = 'application/vnd.oasis.opendocument.graphics';
  449. $mimes['odi'][] = 'application/vnd.oasis.opendocument.image';
  450. $mimes['odm'][] = 'application/vnd.oasis.opendocument.text-master';
  451. $mimes['odp'][] = 'application/vnd.oasis.opendocument.presentation';
  452. $mimes['ods'][] = 'application/vnd.oasis.opendocument.spreadsheet';
  453. $mimes['odt'][] = 'application/vnd.oasis.opendocument.text';
  454. $mimes['ogg'][] = 'application/ogg';
  455. $mimes['ogx'][] = 'application/ogg';
  456. $mimes['oga'][] = 'audio/ogg';
  457. $mimes['ogv'][] = 'video/ogg';
  458. $mimes['old'][] = 'application/x-trash';
  459. $mimes['oleo'][] = 'application/x-oleo';
  460. $mimes['otg'][] = 'application/vnd.oasis.opendocument.graphics-template';
  461. $mimes['oth'][] = 'application/vnd.oasis.opendocument.text-web';
  462. $mimes['otp'][] = 'application/vnd.oasis.opendocument.presentation-template';
  463. $mimes['ots'][] = 'application/vnd.oasis.opendocument.spreadsheet-template';
  464. $mimes['ott'][] = 'application/vnd.oasis.opendocument.text-template';
  465. $mimes['p'][] = 'text/x-pascal';
  466. $mimes['p12'][] = 'application/x-pkcs12';
  467. $mimes['p7s'][] = 'application/pkcs7-signature';
  468. $mimes['pas'][] = 'text/x-pascal';
  469. $mimes['patch'][] = 'text/x-patch';
  470. $mimes['pbm'][] = 'image/x-portable-bitmap';
  471. $mimes['pcd'][] = 'image/x-photo-cd';
  472. $mimes['pcf'][] = 'application/x-font-pcf';
  473. $mimes['pcf.Z'][] = 'application/x-font-type1';
  474. $mimes['pcl'][] = 'application/vnd.hp-pcl';
  475. $mimes['pdb'][] = 'application/vnd.palm';
  476. $mimes['pdf'][] = 'application/pdf';
  477. $mimes['pdf'][] = 'application/x-pdf';
  478. $mimes['pem'][] = 'application/x-x509-ca-cert';
  479. $mimes['perl'][] = 'application/x-perl';
  480. $mimes['pfa'][] = 'application/x-font-type1';
  481. $mimes['pfb'][] = 'application/x-font-type1';
  482. $mimes['pfx'][] = 'application/x-pkcs12';
  483. $mimes['pgm'][] = 'image/x-portable-graymap';
  484. $mimes['pgn'][] = 'application/x-chess-pgn';
  485. $mimes['pgp'][] = 'application/pgp';
  486. $mimes['php'][] = 'application/x-php';
  487. $mimes['php3'][] = 'application/x-php';
  488. $mimes['php4'][] = 'application/x-php';
  489. $mimes['pict'][] = 'image/x-pict';
  490. $mimes['pict1'][] = 'image/x-pict';
  491. $mimes['pict2'][] = 'image/x-pict';
  492. $mimes['pl'][] = 'application/x-perl';
  493. $mimes['pls'][] = 'audio/x-scpls';
  494. $mimes['pm'][] = 'application/x-perl';
  495. $mimes['png'][] = 'image/png';
  496. $mimes['png'][] = 'image/x-png'; // IE
  497. $mimes['pnm'][] = 'image/x-portable-anymap';
  498. $mimes['po'][] = 'text/x-gettext-translation';
  499. $mimes['pot'][] = 'application/vnd.ms-powerpoint';
  500. $mimes['ppm'][] = 'image/x-portable-pixmap';
  501. $mimes['pps'][] = 'application/vnd.ms-powerpoint';
  502. $mimes['ppt'][] = 'application/vnd.ms-powerpoint';
  503. $mimes['ppz'][] = 'application/vnd.ms-powerpoint';
  504. $mimes['ps'][] = 'application/postscript';
  505. $mimes['ps.gz'][] = 'application/x-gzpostscript';
  506. $mimes['psd'][] = 'image/x-psd';
  507. $mimes['psf'][] = 'application/x-font-linux-psf';
  508. $mimes['psid'][] = 'audio/prs.sid';
  509. $mimes['pw'][] = 'application/x-pw';
  510. $mimes['py'][] = 'application/x-python';
  511. $mimes['pyc'][] = 'application/x-python-bytecode';
  512. $mimes['pyo'][] = 'application/x-python-bytecode';
  513. $mimes['qif'][] = 'application/x-qw';
  514. $mimes['qt'][] = 'video/quicktime';
  515. $mimes['qtvr'][] = 'video/quicktime';
  516. $mimes['ra'][] = 'audio/x-pn-realaudio';
  517. $mimes['ram'][] = 'audio/x-pn-realaudio';
  518. $mimes['rar'][] = 'application/x-rar';
  519. $mimes['ras'][] = 'image/x-cmu-raster';
  520. $mimes['rdf'][] = 'text/rdf';
  521. $mimes['rej'][] = 'application/x-reject';
  522. $mimes['rgb'][] = 'image/x-rgb';
  523. $mimes['rle'][] = 'image/rle';
  524. $mimes['rm'][] = 'audio/x-pn-realaudio';
  525. $mimes['roff'][] = 'application/x-troff';
  526. $mimes['rpm'][] = 'application/x-rpm';
  527. $mimes['rss'][] = 'text/rss';
  528. $mimes['rtf'][] = 'application/rtf';
  529. $mimes['rtx'][] = 'text/richtext';
  530. $mimes['s3m'][] = 'audio/x-s3m';
  531. $mimes['sam'][] = 'application/x-amipro';
  532. $mimes['scm'][] = 'text/x-scheme';
  533. $mimes['sda'][] = 'application/vnd.stardivision.draw';
  534. $mimes['sdc'][] = 'application/vnd.stardivision.calc';
  535. $mimes['sdd'][] = 'application/vnd.stardivision.impress';
  536. $mimes['sdp'][] = 'application/vnd.stardivision.impress';
  537. $mimes['sds'][] = 'application/vnd.stardivision.chart';
  538. $mimes['sdw'][] = 'application/vnd.stardivision.writer';
  539. $mimes['sgi'][] = 'image/x-sgi';
  540. $mimes['sgl'][] = 'application/vnd.stardivision.writer';
  541. $mimes['sgm'][] = 'text/sgml';
  542. $mimes['sgml'][] = 'text/sgml';
  543. $mimes['sh'][] = 'application/x-shellscript';
  544. $mimes['shar'][] = 'application/x-shar';
  545. $mimes['shtml'][] = 'text/html';
  546. $mimes['siag'][] = 'application/x-siag';
  547. $mimes['sid'][] = 'audio/prs.sid';
  548. $mimes['sik'][] = 'application/x-trash';
  549. $mimes['silo'][] = 'model/mesh';
  550. $mimes['sit'][] = 'application/x-stuffit';
  551. $mimes['skd'][] = 'application/x-koan';
  552. $mimes['skm'][] = 'application/x-koan';
  553. $mimes['skp'][] = 'application/x-koan';
  554. $mimes['skt'][] = 'application/x-koan';
  555. $mimes['slk'][] = 'text/spreadsheet';
  556. $mimes['smd'][] = 'application/vnd.stardivision.mail';
  557. $mimes['smf'][] = 'application/vnd.stardivision.math';
  558. $mimes['smi'][] = 'application/smil';
  559. $mimes['smil'][] = 'application/smil';
  560. $mimes['sml'][] = 'application/smil';
  561. $mimes['sms'][] = 'application/x-sms-rom';
  562. $mimes['snd'][] = 'audio/basic';
  563. $mimes['so'][] = 'application/x-sharedlib';
  564. $mimes['spd'][] = 'application/x-font-speedo';
  565. $mimes['spl'][] = 'application/x-futuresplash';
  566. $mimes['sql'][] = 'text/x-sql';
  567. $mimes['src'][] = 'application/x-wais-source';
  568. $mimes['stc'][] = 'application/vnd.sun.xml.calc.template';
  569. $mimes['std'][] = 'application/vnd.sun.xml.draw.template';
  570. $mimes['sti'][] = 'application/vnd.sun.xml.impress.template';
  571. $mimes['stm'][] = 'audio/x-stm';
  572. $mimes['stw'][] = 'application/vnd.sun.xml.writer.template';
  573. $mimes['sty'][] = 'text/x-tex';
  574. $mimes['sun'][] = 'image/x-sun-raster';
  575. $mimes['sv4cpio'][] = 'application/x-sv4cpio';
  576. $mimes['sv4crc'][] = 'application/x-sv4crc';
  577. $mimes['svg'][] = 'image/svg+xml';
  578. $mimes['swf'][] = 'application/x-shockwave-flash';
  579. $mimes['sxc'][] = 'application/vnd.sun.xml.calc';
  580. $mimes['sxd'][] = 'application/vnd.sun.xml.draw';
  581. $mimes['sxg'][] = 'application/vnd.sun.xml.writer.global';
  582. $mimes['sxi'][] = 'application/vnd.sun.xml.impress';
  583. $mimes['sxm'][] = 'application/vnd.sun.xml.math';
  584. $mimes['sxw'][] = 'application/vnd.sun.xml.writer';
  585. $mimes['sylk'][] = 'text/spreadsheet';
  586. $mimes['t'][] = 'application/x-troff';
  587. $mimes['tar'][] = 'application/x-tar';
  588. $mimes['tar.Z'][] = 'application/x-tarz';
  589. $mimes['tar.bz'][] = 'application/x-bzip-compressed-tar';
  590. $mimes['tar.bz2'][] = 'application/x-bzip-compressed-tar';
  591. $mimes['tar.gz'][] = 'application/x-compressed-tar';
  592. $mimes['tar.gz'][] = 'application/x-compressed'; // IE
  593. $mimes['tar.lzo'][] = 'application/x-tzo';
  594. $mimes['tcl'][] = 'text/x-tcl';
  595. $mimes['tex'][] = 'text/x-tex';
  596. $mimes['texi'][] = 'text/x-texinfo';
  597. $mimes['texinfo'][] = 'text/x-texinfo';
  598. $mimes['tga'][] = 'image/x-tga';
  599. $mimes['tgz'][] = 'application/x-compressed-tar';
  600. $mimes['theme'][] = 'application/x-theme';
  601. $mimes['tif'][] = 'image/tiff';
  602. $mimes['tiff'][] = 'image/tiff';
  603. $mimes['tk'][] = 'text/x-tcl';
  604. $mimes['torrent'][] = 'application/x-bittorrent';
  605. $mimes['tr'][] = 'application/x-troff';
  606. $mimes['ts'][] = 'application/x-linguist';
  607. $mimes['tsv'][] = 'text/tab-separated-values';
  608. $mimes['ttf'][] = 'application/x-font-ttf';
  609. $mimes['txt'][] = 'text/plain';
  610. $mimes['tzo'][] = 'application/x-tzo';
  611. $mimes['ui'][] = 'application/x-designer';
  612. $mimes['uil'][] = 'text/x-uil';
  613. $mimes['ult'][] = 'audio/x-mod';
  614. $mimes['uni'][] = 'audio/x-mod';
  615. $mimes['unity3d'][] = 'application/octet-stream';
  616. $mimes['uri'][] = 'text/x-uri';
  617. $mimes['url'][] = 'text/x-uri';
  618. $mimes['ustar'][] = 'application/x-ustar';
  619. $mimes['vcd'][] = 'application/x-cdlink';
  620. $mimes['vcf'][] = 'text/x-vcalendar';
  621. $mimes['vcs'][] = 'text/x-vcalendar';
  622. $mimes['vct'][] = 'text/x-vcard';
  623. $mimes['vfb'][] = 'text/calendar';
  624. $mimes['vob'][] = 'video/mpeg';
  625. $mimes['voc'][] = 'audio/x-voc';
  626. $mimes['vor'][] = 'application/vnd.stardivision.writer';
  627. $mimes['vrml'][] = 'model/vrml';
  628. $mimes['vsd'][] = 'application/vnd.visio';
  629. $mimes['wav'][] = 'audio/x-wav';
  630. $mimes['wav'][] = 'audio/wav'; // IE
  631. $mimes['wax'][] = 'audio/x-ms-wax';
  632. $mimes['wb1'][] = 'application/x-quattropro';
  633. $mimes['wb2'][] = 'application/x-quattropro';
  634. $mimes['wb3'][] = 'application/x-quattropro';
  635. $mimes['wbmp'][] = 'image/vnd.wap.wbmp';
  636. $mimes['wbxml'][] = 'application/vnd.wap.wbxml';
  637. $mimes['wk1'][] = 'application/vnd.lotus-1-2-3';
  638. $mimes['wk3'][] = 'application/vnd.lotus-1-2-3';
  639. $mimes['wk4'][] = 'application/vnd.lotus-1-2-3';
  640. $mimes['wks'][] = 'application/vnd.lotus-1-2-3';
  641. $mimes['wm'][] = 'video/x-ms-wm';
  642. $mimes['wma'][] = 'audio/x-ms-wma';
  643. $mimes['wmd'][] = 'application/x-ms-wmd';
  644. $mimes['wmf'][] = 'image/x-wmf';
  645. $mimes['wml'][] = 'text/vnd.wap.wml';
  646. $mimes['wmlc'][] = 'application/vnd.wap.wmlc';
  647. $mimes['wmls'][] = 'text/vnd.wap.wmlscript';
  648. $mimes['wmlsc'][] = 'application/vnd.wap.wmlscriptc';
  649. $mimes['wmv'][] = 'video/x-ms-wmv';
  650. $mimes['wmx'][] = 'video/x-ms-wmx';
  651. $mimes['wmz'][] = 'application/x-ms-wmz';
  652. $mimes['wpd'][] = 'application/wordperfect';
  653. $mimes['wpg'][] = 'application/x-wpg';
  654. $mimes['wri'][] = 'application/x-mswrite';
  655. $mimes['wrl'][] = 'model/vrml';
  656. $mimes['wvx'][] = 'video/x-ms-wvx';
  657. $mimes['xac'][] = 'application/x-gnucash';
  658. $mimes['xbel'][] = 'application/x-xbel';
  659. $mimes['xbm'][] = 'image/x-xbitmap';
  660. $mimes['xcf'][] = 'image/x-xcf';
  661. $mimes['xcf.bz2'][] = 'image/x-compressed-xcf';
  662. $mimes['xcf.gz'][] = 'image/x-compressed-xcf';
  663. $mimes['xht'][] = 'application/xhtml+xml';
  664. $mimes['xhtml'][] = 'application/xhtml+xml';
  665. $mimes['xi'][] = 'audio/x-xi';
  666. $mimes['xls'][] = 'application/vnd.ms-excel';
  667. $mimes['xla'][] = 'application/vnd.ms-excel';
  668. $mimes['xlc'][] = 'application/vnd.ms-excel';
  669. $mimes['xld'][] = 'application/vnd.ms-excel';
  670. $mimes['xll'][] = 'application/vnd.ms-excel';
  671. $mimes['xlm'][] = 'application/vnd.ms-excel';
  672. $mimes['xlt'][] = 'application/vnd.ms-excel';
  673. $mimes['xlw'][] = 'application/vnd.ms-excel';
  674. $mimes['xm'][] = 'audio/x-xm';
  675. $mimes['xml'][] = 'text/xml';
  676. $mimes['xml'][] = 'application/xml'; // IE
  677. $mimes['xpm'][] = 'image/x-xpixmap';
  678. $mimes['xsl'][] = 'text/x-xslt';
  679. $mimes['xslfo'][] = 'text/x-xslfo';
  680. $mimes['xslt'][] = 'text/x-xslt';
  681. $mimes['xwd'][] = 'image/x-xwindowdump';
  682. $mimes['xyz'][] = 'chemical/x-xyz';
  683. $mimes['zabw'][] = 'application/x-abiword';
  684. $mimes['zip'][] = 'application/zip';
  685. $mimes['zip'][] = 'application/x-zip';
  686. $mimes['zip'][] = 'application/x-zip-compressed'; // IE
  687. $mimes['zoo'][] = 'application/x-zoo';
  688. $mimes['123'][] = 'application/vnd.lotus-1-2-3';
  689. $mimes['669'][] = 'audio/x-mod';
  690. // office 2007
  691. $mimes['docm'][] = 'application/vnd.ms-word.document.macroEnabled.12';
  692. $mimes['docx'][] = 'application/vnd.openxmlformats-officedocument.wordprocessingml.document';
  693. $mimes['dotm'][] = 'application/vnd.ms-word.template.macroEnabled.12';
  694. $mimes['dotx'][] = 'application/vnd.openxmlformats-officedocument.wordprocessingml.template';
  695. $mimes['potm'][] = 'application/vnd.ms-powerpoint.template.macroEnabled.12';
  696. $mimes['potx'][] = 'application/vnd.openxmlformats-officedocument.presentationml.template';
  697. $mimes['ppam'][] = 'application/vnd.ms-powerpoint.addin.macroEnabled.12';
  698. $mimes['ppsm'][] = 'application/vnd.ms-powerpoint.slideshow.macroEnabled.12';
  699. $mimes['ppsx'][] = 'application/vnd.openxmlformats-officedocument.presentationml.slideshow';
  700. $mimes['pptm'][] = 'application/vnd.ms-powerpoint.presentation.macroEnabled.12';
  701. $mimes['pptx'][] = 'application/vnd.openxmlformats-officedocument.presentationml.presentation';
  702. $mimes['xlam'][] = 'application/vnd.ms-excel.addin.macroEnabled.12';
  703. $mimes['xlsb'][] = 'application/vnd.ms-excel.sheet.binary.macroEnabled.12';
  704. $mimes['xlsm'][] = 'application/vnd.ms-excel.sheet.macroEnabled.12';
  705. $mimes['xlsx'][] = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
  706. $mimes['xltm'][] = 'application/vnd.ms-excel.template.macroEnabled.12';
  707. $mimes['xltx'][] = 'application/vnd.openxmlformats-officedocument.spreadsheetml.template';
  708. return $mimes;
  709. }
  710. }