A modest collection of PHP libraries used at SparkFun.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

91 lines
2.6 KiB

  1. <?php
  2. namespace SparkLib\Util;
  3. /**
  4. * A utility class to map mime types to extensions and vice-versa.
  5. *
  6. * This is not meant to be comprehensive - just the ones we come across regularly.
  7. *
  8. * Based in part on debian's /etc/mime.types
  9. **/
  10. class Mime {
  11. public static $mimeToExtension = array(
  12. // the usuals
  13. 'image/jpeg' => 'jpg',
  14. 'image/png' => 'png',
  15. 'image/tiff' => 'tiff',
  16. 'image/gif' => 'gif',
  17. // pdf
  18. 'applications/vnd.pdf' => 'pdf',
  19. 'application/acrobat' => 'pdf',
  20. 'application/x-pdf' => 'pdf',
  21. 'application/pdf' => 'pdf',
  22. 'text/x-pdf' => 'pdf',
  23. 'text/pdf' => 'pdf',
  24. // odt
  25. 'application/vnd.oasis.opendocument.text' => 'odt',
  26. 'application/x-vnd.oasis.opendocument.text' => 'odt',
  27. // zip
  28. 'application/x-zip-compressed' => 'zip',
  29. 'application/x-compressed' => 'zip',
  30. 'application/octet-stream' => 'zip',
  31. 'application/x-compress' => 'zip',
  32. 'application/x-zip' => 'zip',
  33. 'application/zip' => 'zip',
  34. 'multipart/x-zip' => 'zip',
  35. // doc
  36. 'application/vnd.ms-word' => 'doc',
  37. 'application/vnd.msword' => 'doc',
  38. 'application/x-msword' => 'doc',
  39. 'application/winword' => 'doc',
  40. 'application/msword' => 'doc',
  41. 'application/x-msw6' => 'doc',
  42. 'application/word' => 'doc',
  43. 'application/doc' => 'doc',
  44. 'appl/text' => 'doc',
  45. // docx
  46. 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' => 'docx',
  47. // ppt
  48. 'application/vnd.ms-powerpoint' => 'ppt',
  49. 'application/vnd-mspowerpoint' => 'ppt',
  50. 'application/ms-powerpoint' => 'ppt',
  51. 'application/mspowerpoint' => 'ppt',
  52. 'application/x-powerpoint' => 'ppt',
  53. 'application/mspowerpnt' => 'ppt',
  54. 'application/powerpoint' => 'ppt',
  55. 'application/mspowerpnt' => 'ppt',
  56. 'application/x-m' => 'ppt',
  57. );
  58. public static $extensionToMime = array(
  59. 'jpg' => 'image/jpeg',
  60. 'png' => 'image/png',
  61. 'tiff' => 'image/tif',
  62. 'pdf' => 'application/pdf',
  63. 'odt' => 'application/vnd.oasis.opendocument.text',
  64. 'zip' => 'application/zip',
  65. 'doc' => 'application/msword',
  66. 'docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
  67. 'ppt' => 'application/vnd.ms-powerpoint',
  68. );
  69. public static function getMime($extension)
  70. {
  71. return self::$extnsionToMime[$extension];
  72. }
  73. public static function getExtension($mime)
  74. {
  75. return self::$mimeToExtension[$mime];
  76. }
  77. }