PageRenderTime 57ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/net/src/lmbMimeType.class.php

http://github.com/limb-php-framework/limb
PHP | 82 lines | 62 code | 7 blank | 13 comment | 2 complexity | bf1e4b57f47d214014e7634cb8b8f537 MD5 | raw file
Possible License(s): LGPL-2.1, AGPL-3.0, MPL-2.0-no-copyleft-exception, GPL-2.0
  1. <?php
  2. /*
  3. * Limb PHP Framework
  4. *
  5. * @link http://limb-project.com
  6. * @copyright Copyright &copy; 2004-2009 BIT(http://bit-creative.com)
  7. * @license LGPL http://www.gnu.org/copyleft/lesser.html
  8. */
  9. /**
  10. * class lmbMimeType.
  11. *
  12. * @package net
  13. * @version $Id: lmbMimeType.class.php 7886 2009-04-17 07:39:04Z serega $
  14. */
  15. class lmbMimeType
  16. {
  17. static protected $mime_types = array(
  18. 'video/avi'=>'avi',
  19. 'application/x-flash-video'=>'flv',
  20. 'audio/x-aiff'=>'aif',
  21. 'audio/x-aiff' => 'aifc',
  22. 'audio/x-aiff' => 'aiff',
  23. 'image/bmp' =>'bmp',
  24. 'application/msword' =>'doc',
  25. 'application/vnd.ms-office' =>'doc',
  26. 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' => 'docx',
  27. 'video/x-flv' =>'flv',
  28. 'image/gif' =>'gif',
  29. 'text/html' =>'html',
  30. 'image/pjpeg' =>'jpeg',
  31. 'image/jpeg' =>'jpg',
  32. 'text/javascript' =>'js',
  33. 'video/mpeg' =>'mpeg',
  34. 'audio/mpeg' =>'mp3',
  35. 'audio/mp3' => 'mp3',
  36. 'video/mpeg' =>'mpg',
  37. 'message/rfc822' =>'msg',
  38. 'application/pdf' =>'pdf',
  39. 'image/png' =>'png',
  40. 'image/x-png' => 'png',
  41. 'application/vnd.ms-powerpoint' =>'ppt',
  42. 'image/psd' =>'psd',
  43. 'text/rtf' =>'rtf',
  44. 'application/x-shockwave-flash' =>'swf',
  45. 'text/plain' =>'txt',
  46. 'audio/x-wav' =>'wav',
  47. 'audio/wav' => 'wav',
  48. 'application/vnd.ms-excel' =>'xls',
  49. 'application/x-rar-compressed' =>'rar',
  50. 'application/rar' =>'rar',
  51. 'application/x-zip-compressed' =>'zip',
  52. 'application/zip' =>'zip'
  53. );
  54. static function getExtension($mime_type)
  55. {
  56. $mime_type = strtolower($mime_type);
  57. return isset(self :: $mime_types[$mime_type])
  58. ? self :: $mime_types[$mime_type]
  59. : null;
  60. }
  61. static function getMimeType($extension)
  62. {
  63. $extension = ltrim(strtolower($extension), '.');
  64. $mime_type = array_search($extension,self :: $mime_types);
  65. return $mime_type ?: null;
  66. }
  67. static function getFileMimeType($file)
  68. {
  69. if($info = pathinfo($file))
  70. {
  71. if(isset($info['extension']))
  72. return self :: getMimeType($info['extension']);
  73. }
  74. }
  75. }