Maison  >  Article  >  développement back-end  >  PHP获得文件的mime type类型

PHP获得文件的mime type类型

WBOY
WBOYoriginal
2016-07-25 08:45:192265parcourir
  1. /**
  2. * 获得文件的mime type类型
  3. * @author xiaobing.meng
  4. *
  5. */
  6. class MimeTypes {
  7. public static $mime_types = array (
  8. 'apk' => 'application/vnd.android.package-archive',
  9. '3gp' => 'video/3gpp',
  10. 'ai' => 'application/postscript',
  11. 'aif' => 'audio/x-aiff',
  12. 'aifc' => 'audio/x-aiff',
  13. 'aiff' => 'audio/x-aiff',
  14. 'asc' => 'text/plain',
  15. 'atom' => 'application/atom+xml',
  16. 'au' => 'audio/basic',
  17. 'avi' => 'video/x-msvideo',
  18. 'bcpio' => 'application/x-bcpio',
  19. 'bin' => 'application/octet-stream',
  20. 'bmp' => 'image/bmp',
  21. 'cdf' => 'application/x-netcdf',
  22. 'cgm' => 'image/cgm',
  23. 'class' => 'application/octet-stream',
  24. 'cpio' => 'application/x-cpio',
  25. 'cpt' => 'application/mac-compactpro',
  26. 'csh' => 'application/x-csh',
  27. 'css' => 'text/css',
  28. 'dcr' => 'application/x-director',
  29. 'dif' => 'video/x-dv',
  30. 'dir' => 'application/x-director',
  31. 'djv' => 'image/vnd.djvu',
  32. 'djvu' => 'image/vnd.djvu',
  33. 'dll' => 'application/octet-stream',
  34. 'dmg' => 'application/octet-stream',
  35. 'dms' => 'application/octet-stream',
  36. 'doc' => 'application/msword',
  37. 'dtd' => 'application/xml-dtd',
  38. 'dv' => 'video/x-dv',
  39. 'dvi' => 'application/x-dvi',
  40. 'dxr' => 'application/x-director',
  41. 'eps' => 'application/postscript',
  42. 'etx' => 'text/x-setext',
  43. 'exe' => 'application/octet-stream',
  44. 'ez' => 'application/andrew-inset',
  45. 'flv' => 'video/x-flv',
  46. 'gif' => 'image/gif',
  47. 'gram' => 'application/srgs',
  48. 'grxml' => 'application/srgs+xml',
  49. 'gtar' => 'application/x-gtar',
  50. 'gz' => 'application/x-gzip',
  51. 'hdf' => 'application/x-hdf',
  52. 'hqx' => 'application/mac-binhex40',
  53. 'htm' => 'text/html',
  54. 'html' => 'text/html',
  55. 'ice' => 'x-conference/x-cooltalk',
  56. 'ico' => 'image/x-icon',
  57. 'ics' => 'text/calendar',
  58. 'ief' => 'image/ief',
  59. 'ifb' => 'text/calendar',
  60. 'iges' => 'model/iges',
  61. 'igs' => 'model/iges',
  62. 'jnlp' => 'application/x-java-jnlp-file',
  63. 'jp2' => 'image/jp2',
  64. 'jpe' => 'image/jpeg',
  65. 'jpeg' => 'image/jpeg',
  66. 'jpg' => 'image/jpeg',
  67. 'js' => 'application/x-javascript',
  68. 'kar' => 'audio/midi',
  69. 'latex' => 'application/x-latex',
  70. 'lha' => 'application/octet-stream',
  71. 'lzh' => 'application/octet-stream',
  72. 'm3u' => 'audio/x-mpegurl',
  73. 'm4a' => 'audio/mp4a-latm',
  74. 'm4p' => 'audio/mp4a-latm',
  75. 'm4u' => 'video/vnd.mpegurl',
  76. 'm4v' => 'video/x-m4v',
  77. 'mac' => 'image/x-macpaint',
  78. 'man' => 'application/x-troff-man',
  79. 'mathml' => 'application/mathml+xml',
  80. 'me' => 'application/x-troff-me',
  81. 'mesh' => 'model/mesh',
  82. 'mid' => 'audio/midi',
  83. 'midi' => 'audio/midi',
  84. 'mif' => 'application/vnd.mif',
  85. 'mov' => 'video/quicktime',
  86. 'movie' => 'video/x-sgi-movie',
  87. 'mp2' => 'audio/mpeg',
  88. 'mp3' => 'audio/mpeg',
  89. 'mp4' => 'video/mp4',
  90. 'mpe' => 'video/mpeg',
  91. 'mpeg' => 'video/mpeg',
  92. 'mpg' => 'video/mpeg',
  93. 'mpga' => 'audio/mpeg',
  94. 'ms' => 'application/x-troff-ms',
  95. 'msh' => 'model/mesh',
  96. 'mxu' => 'video/vnd.mpegurl',
  97. 'nc' => 'application/x-netcdf',
  98. 'oda' => 'application/oda',
  99. 'ogg' => 'application/ogg',
  100. 'ogv' => 'video/ogv',
  101. 'pbm' => 'image/x-portable-bitmap',
  102. 'pct' => 'image/pict',
  103. 'pdb' => 'chemical/x-pdb',
  104. 'pdf' => 'application/pdf',
  105. 'pgm' => 'image/x-portable-graymap',
  106. 'pgn' => 'application/x-chess-pgn',
  107. 'pic' => 'image/pict',
  108. 'pict' => 'image/pict',
  109. 'png' => 'image/png',
  110. 'pnm' => 'image/x-portable-anymap',
  111. 'pnt' => 'image/x-macpaint',
  112. 'pntg' => 'image/x-macpaint',
  113. 'ppm' => 'image/x-portable-pixmap',
  114. 'ppt' => 'application/vnd.ms-powerpoint',
  115. 'ps' => 'application/postscript',
  116. 'qt' => 'video/quicktime',
  117. 'qti' => 'image/x-quicktime',
  118. 'qtif' => 'image/x-quicktime',
  119. 'ra' => 'audio/x-pn-realaudio',
  120. 'ram' => 'audio/x-pn-realaudio',
  121. 'ras' => 'image/x-cmu-raster',
  122. 'rdf' => 'application/rdf+xml',
  123. 'rgb' => 'image/x-rgb',
  124. 'rm' => 'application/vnd.rn-realmedia',
  125. 'roff' => 'application/x-troff',
  126. 'rtf' => 'text/rtf',
  127. 'rtx' => 'text/richtext',
  128. 'sgm' => 'text/sgml',
  129. 'sgml' => 'text/sgml',
  130. 'sh' => 'application/x-sh',
  131. 'shar' => 'application/x-shar',
  132. 'silo' => 'model/mesh',
  133. 'sit' => 'application/x-stuffit',
  134. 'skd' => 'application/x-koan',
  135. 'skm' => 'application/x-koan',
  136. 'skp' => 'application/x-koan',
  137. 'skt' => 'application/x-koan',
  138. 'smi' => 'application/smil',
  139. 'smil' => 'application/smil',
  140. 'snd' => 'audio/basic',
  141. 'so' => 'application/octet-stream',
  142. 'spl' => 'application/x-futuresplash',
  143. 'src' => 'application/x-wais-source',
  144. 'sv4cpio' => 'application/x-sv4cpio',
  145. 'sv4crc' => 'application/x-sv4crc',
  146. 'svg' => 'image/svg+xml',
  147. 'swf' => 'application/x-shockwave-flash',
  148. 't' => 'application/x-troff',
  149. 'tar' => 'application/x-tar',
  150. 'tcl' => 'application/x-tcl',
  151. 'tex' => 'application/x-tex',
  152. 'texi' => 'application/x-texinfo',
  153. 'texinfo' => 'application/x-texinfo',
  154. 'tif' => 'image/tiff',
  155. 'tiff' => 'image/tiff',
  156. 'tr' => 'application/x-troff',
  157. 'tsv' => 'text/tab-separated-values',
  158. 'txt' => 'text/plain',
  159. 'ustar' => 'application/x-ustar',
  160. 'vcd' => 'application/x-cdlink',
  161. 'vrml' => 'model/vrml',
  162. 'vxml' => 'application/voicexml+xml',
  163. 'wav' => 'audio/x-wav',
  164. 'wbmp' => 'image/vnd.wap.wbmp',
  165. 'wbxml' => 'application/vnd.wap.wbxml',
  166. 'webm' => 'video/webm',
  167. 'wml' => 'text/vnd.wap.wml',
  168. 'wmlc' => 'application/vnd.wap.wmlc',
  169. 'wmls' => 'text/vnd.wap.wmlscript',
  170. 'wmlsc' => 'application/vnd.wap.wmlscriptc',
  171. 'wmv' => 'video/x-ms-wmv',
  172. 'wrl' => 'model/vrml',
  173. 'xbm' => 'image/x-xbitmap',
  174. 'xht' => 'application/xhtml+xml',
  175. 'xhtml' => 'application/xhtml+xml',
  176. 'xls' => 'application/vnd.ms-excel',
  177. 'xml' => 'application/xml',
  178. 'xpm' => 'image/x-xpixmap',
  179. 'xsl' => 'application/xml',
  180. 'xslt' => 'application/xslt+xml',
  181. 'xul' => 'application/vnd.mozilla.xul+xml',
  182. 'xwd' => 'image/x-xwindowdump',
  183. 'xyz' => 'chemical/x-xyz',
  184. 'zip' => 'application/zip' );
  185. public static function get_mimetype($ext) {
  186. return (isset ( self::$mime_types [$ext] ) ? self::$mime_types [$ext] : 'application/octet-stream');
  187. }
  188. }
复制代码

PHP, mime, type


Déclaration:
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn
Article précédent:PHP终极加密功能 Article suivant:PHP数组生成 CSV 文件