PageRenderTime 48ms CodeModel.GetById 25ms RepoModel.GetById 1ms app.codeStats 0ms

/inc/popoon/helpers/mimetypes.php

https://github.com/chregu/fluxcms
PHP | 81 lines | 72 code | 9 blank | 0 comment | 6 complexity | a231c4d9a9e5737b90e46c1167cb117a MD5 | raw file
Possible License(s): GPL-2.0, BSD-3-Clause, Apache-2.0, LGPL-2.1
  1. <?php
  2. class popoon_helpers_mimetypes {
  3. static function getFromFileLocation($src) {
  4. $extension = strtolower(substr($src,strrpos($src,".")+1));
  5. if ($src == ".") {
  6. return "httpd/unix-directory";
  7. }
  8. switch ($extension) {
  9. case "gif":
  10. return "image/gif";
  11. case "jpg":
  12. case "jpeg":
  13. return "image/jpeg";
  14. case "png":
  15. return "image/png";
  16. case "css":
  17. return "text/css";
  18. case "xml":
  19. case "xsl":
  20. case "xsd":
  21. case "rng":
  22. case "tal":
  23. case "configxml":
  24. case "children":
  25. return "text/xml";
  26. case "js":
  27. return "text/javascript";
  28. case "html":
  29. case "htm":
  30. case "xhtml":
  31. return "text/html";
  32. case "txt":
  33. return "text/plain";
  34. case "pdf":
  35. return "application/pdf";
  36. case "zip":
  37. return "application/zip";
  38. case "gz":
  39. case "tgz":
  40. return "application/x-gzip";
  41. case "bz2":
  42. return "application/x-bz2";
  43. case "tar":
  44. return "application/x-gtar";
  45. case "torrent":
  46. return "application/x-bittorrent";
  47. case "mp3":
  48. return "audio/mpeg";
  49. case "doc":
  50. return "application/msword";
  51. case "xls":
  52. return "application/vnd.ms-excel";
  53. case "ppt":
  54. return "application/vnd.ms-powerpoint";
  55. default:
  56. if (strpos($src,"://") == false && file_exists($src)) {
  57. if (function_exists("finfo_open")) {
  58. $res = finfo_open(FILEINFO_MIME);
  59. $m = finfo_file($res, $src);
  60. finfo_close($res);
  61. } elseif(!strpos(ini_get('disable_functions'),'exec')) {
  62. exec(escapeshellcmd('file -ib '. escapeshellarg($src)), $out);
  63. $m = array_shift($out);
  64. }
  65. if (isset($m)) {
  66. return $m;
  67. }
  68. }
  69. return "application/octet-stream";
  70. }
  71. }
  72. }