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.
 
 
 
 

257 lines
11 KiB

  1. <?php
  2. namespace Kuxin\Helper;
  3. class File
  4. {
  5. private static $mime_types = [
  6. 'xlsx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
  7. 'xltx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.template',
  8. 'potx' => 'application/vnd.openxmlformats-officedocument.presentationml.template',
  9. 'ppsx' => 'application/vnd.openxmlformats-officedocument.presentationml.slideshow',
  10. 'pptx' => 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
  11. 'sldx' => 'application/vnd.openxmlformats-officedocument.presentationml.slide',
  12. 'docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
  13. 'dotx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.template',
  14. 'xlam' => 'application/vnd.ms-excel.addin.macroEnabled.12',
  15. 'xlsb' => 'application/vnd.ms-excel.sheet.binary.macroEnabled.12',
  16. 'apk' => 'application/vnd.android.package-archive',
  17. 'hqx' => 'application/mac-binhex40',
  18. 'cpt' => 'application/mac-compactpro',
  19. 'doc' => 'application/msword',
  20. 'ogg' => 'audio/ogg',
  21. 'pdf' => 'application/pdf',
  22. 'rtf' => 'text/rtf',
  23. 'mif' => 'application/vnd.mif',
  24. 'xls' => 'application/vnd.ms-excel',
  25. 'ppt' => 'application/vnd.ms-powerpoint',
  26. 'odc' => 'application/vnd.oasis.opendocument.chart',
  27. 'odb' => 'application/vnd.oasis.opendocument.database',
  28. 'odf' => 'application/vnd.oasis.opendocument.formula',
  29. 'odg' => 'application/vnd.oasis.opendocument.graphics',
  30. 'otg' => 'application/vnd.oasis.opendocument.graphics-template',
  31. 'odi' => 'application/vnd.oasis.opendocument.image',
  32. 'odp' => 'application/vnd.oasis.opendocument.presentation',
  33. 'otp' => 'application/vnd.oasis.opendocument.presentation-template',
  34. 'ods' => 'application/vnd.oasis.opendocument.spreadsheet',
  35. 'ots' => 'application/vnd.oasis.opendocument.spreadsheet-template',
  36. 'odt' => 'application/vnd.oasis.opendocument.text',
  37. 'odm' => 'application/vnd.oasis.opendocument.text-master',
  38. 'ott' => 'application/vnd.oasis.opendocument.text-template',
  39. 'oth' => 'application/vnd.oasis.opendocument.text-web',
  40. 'sxw' => 'application/vnd.sun.xml.writer',
  41. 'stw' => 'application/vnd.sun.xml.writer.template',
  42. 'sxc' => 'application/vnd.sun.xml.calc',
  43. 'stc' => 'application/vnd.sun.xml.calc.template',
  44. 'sxd' => 'application/vnd.sun.xml.draw',
  45. 'std' => 'application/vnd.sun.xml.draw.template',
  46. 'sxi' => 'application/vnd.sun.xml.impress',
  47. 'sti' => 'application/vnd.sun.xml.impress.template',
  48. 'sxg' => 'application/vnd.sun.xml.writer.global',
  49. 'sxm' => 'application/vnd.sun.xml.math',
  50. 'sis' => 'application/vnd.symbian.install',
  51. 'wbxml' => 'application/vnd.wap.wbxml',
  52. 'wmlc' => 'application/vnd.wap.wmlc',
  53. 'wmlsc' => 'application/vnd.wap.wmlscriptc',
  54. 'bcpio' => 'application/x-bcpio',
  55. 'torrent' => 'application/x-bittorrent',
  56. 'bz2' => 'application/x-bzip2',
  57. 'vcd' => 'application/x-cdlink',
  58. 'pgn' => 'application/x-chess-pgn',
  59. 'cpio' => 'application/x-cpio',
  60. 'csh' => 'application/x-csh',
  61. 'dvi' => 'application/x-dvi',
  62. 'spl' => 'application/x-futuresplash',
  63. 'gtar' => 'application/x-gtar',
  64. 'hdf' => 'application/x-hdf',
  65. 'jar' => 'application/java-archive',
  66. 'jnlp' => 'application/x-java-jnlp-file',
  67. 'js' => 'application/javascript',
  68. 'json' => 'application/json',
  69. 'ksp' => 'application/x-kspread',
  70. 'chrt' => 'application/x-kchart',
  71. 'kil' => 'application/x-killustrator',
  72. 'latex' => 'application/x-latex',
  73. 'rpm' => 'application/x-rpm',
  74. 'sh' => 'application/x-sh',
  75. 'shar' => 'application/x-shar',
  76. 'swf' => 'application/x-shockwave-flash',
  77. 'sit' => 'application/x-stuffit',
  78. 'sv4cpio' => 'application/x-sv4cpio',
  79. 'sv4crc' => 'application/x-sv4crc',
  80. 'tar' => 'application/x-tar',
  81. 'tcl' => 'application/x-tcl',
  82. 'tex' => 'application/x-tex',
  83. 'man' => 'application/x-troff-man',
  84. 'me' => 'application/x-troff-me',
  85. 'ms' => 'application/x-troff-ms',
  86. 'ustar' => 'application/x-ustar',
  87. 'src' => 'application/x-wais-source',
  88. 'zip' => 'application/zip',
  89. 'm3u' => 'audio/x-mpegurl',
  90. 'ra' => 'audio/x-pn-realaudio',
  91. 'wav' => 'audio/x-wav',
  92. 'wma' => 'audio/x-ms-wma',
  93. 'wax' => 'audio/x-ms-wax',
  94. 'pdb' => 'chemical/x-pdb',
  95. 'xyz' => 'chemical/x-xyz',
  96. 'bmp' => 'image/bmp',
  97. 'gif' => 'image/gif',
  98. 'ief' => 'image/ief',
  99. 'png' => 'image/png',
  100. 'wbmp' => 'image/vnd.wap.wbmp',
  101. 'ras' => 'image/x-cmu-raster',
  102. 'pnm' => 'image/x-portable-anymap',
  103. 'pbm' => 'image/x-portable-bitmap',
  104. 'pgm' => 'image/x-portable-graymap',
  105. 'ppm' => 'image/x-portable-pixmap',
  106. 'rgb' => 'image/x-rgb',
  107. 'xbm' => 'image/x-xbitmap',
  108. 'xpm' => 'image/x-xpixmap',
  109. 'xwd' => 'image/x-xwindowdump',
  110. 'css' => 'text/css',
  111. 'rtx' => 'text/richtext',
  112. 'tsv' => 'text/tab-separated-values',
  113. 'jad' => 'text/vnd.sun.j2me.app-descriptor',
  114. 'wml' => 'text/vnd.wap.wml',
  115. 'wmls' => 'text/vnd.wap.wmlscript',
  116. 'etx' => 'text/x-setext',
  117. 'mxu' => 'video/vnd.mpegurl',
  118. 'flv' => 'video/x-flv',
  119. 'wm' => 'video/x-ms-wm',
  120. 'wmv' => 'video/x-ms-wmv',
  121. 'wmx' => 'video/x-ms-wmx',
  122. 'wvx' => 'video/x-ms-wvx',
  123. 'avi' => 'video/x-msvideo',
  124. 'movie' => 'video/x-sgi-movie',
  125. 'ice' => 'x-conference/x-cooltalk',
  126. '3gp' => 'video/3gpp',
  127. 'ai' => 'application/postscript',
  128. 'aif' => 'audio/x-aiff',
  129. 'aifc' => 'audio/x-aiff',
  130. 'aiff' => 'audio/x-aiff',
  131. 'asc' => 'text/plain',
  132. 'atom' => 'application/atom+xml',
  133. 'au' => 'audio/basic',
  134. 'bin' => 'application/octet-stream',
  135. 'cdf' => 'application/x-netcdf',
  136. 'cgm' => 'image/cgm',
  137. 'class' => 'application/octet-stream',
  138. 'dcr' => 'application/x-director',
  139. 'dif' => 'video/x-dv',
  140. 'dir' => 'application/x-director',
  141. 'djv' => 'image/vnd.djvu',
  142. 'djvu' => 'image/vnd.djvu',
  143. 'dll' => 'application/octet-stream',
  144. 'dmg' => 'application/octet-stream',
  145. 'dms' => 'application/octet-stream',
  146. 'dtd' => 'application/xml-dtd',
  147. 'dv' => 'video/x-dv',
  148. 'dxr' => 'application/x-director',
  149. 'eps' => 'application/postscript',
  150. 'exe' => 'application/octet-stream',
  151. 'ez' => 'application/andrew-inset',
  152. 'gram' => 'application/srgs',
  153. 'grxml' => 'application/srgs+xml',
  154. 'gz' => 'application/x-gzip',
  155. 'htm' => 'text/html',
  156. 'html' => 'text/html',
  157. 'ico' => 'image/x-icon',
  158. 'ics' => 'text/calendar',
  159. 'ifb' => 'text/calendar',
  160. 'iges' => 'model/iges',
  161. 'igs' => 'model/iges',
  162. 'jp2' => 'image/jp2',
  163. 'jpe' => 'image/jpeg',
  164. 'jpeg' => 'image/jpeg',
  165. 'jpg' => 'image/jpeg',
  166. 'kar' => 'audio/midi',
  167. 'lha' => 'application/octet-stream',
  168. 'lzh' => 'application/octet-stream',
  169. 'm4a' => 'audio/mp4a-latm',
  170. 'm4p' => 'audio/mp4a-latm',
  171. 'm4u' => 'video/vnd.mpegurl',
  172. 'm4v' => 'video/x-m4v',
  173. 'mac' => 'image/x-macpaint',
  174. 'mathml' => 'application/mathml+xml',
  175. 'mesh' => 'model/mesh',
  176. 'mid' => 'audio/midi',
  177. 'midi' => 'audio/midi',
  178. 'mov' => 'video/quicktime',
  179. 'mp2' => 'audio/mpeg',
  180. 'mp3' => 'audio/mpeg',
  181. 'mp4' => 'video/mp4',
  182. 'mpe' => 'video/mpeg',
  183. 'mpeg' => 'video/mpeg',
  184. 'mpg' => 'video/mpeg',
  185. 'mpga' => 'audio/mpeg',
  186. 'msh' => 'model/mesh',
  187. 'nc' => 'application/x-netcdf',
  188. 'oda' => 'application/oda',
  189. 'ogv' => 'video/ogv',
  190. 'pct' => 'image/pict',
  191. 'pic' => 'image/pict',
  192. 'pict' => 'image/pict',
  193. 'pnt' => 'image/x-macpaint',
  194. 'pntg' => 'image/x-macpaint',
  195. 'ps' => 'application/postscript',
  196. 'qt' => 'video/quicktime',
  197. 'qti' => 'image/x-quicktime',
  198. 'qtif' => 'image/x-quicktime',
  199. 'ram' => 'audio/x-pn-realaudio',
  200. 'rdf' => 'application/rdf+xml',
  201. 'rm' => 'application/vnd.rn-realmedia',
  202. 'roff' => 'application/x-troff',
  203. 'sgm' => 'text/sgml',
  204. 'sgml' => 'text/sgml',
  205. 'silo' => 'model/mesh',
  206. 'skd' => 'application/x-koan',
  207. 'skm' => 'application/x-koan',
  208. 'skp' => 'application/x-koan',
  209. 'skt' => 'application/x-koan',
  210. 'smi' => 'application/smil',
  211. 'smil' => 'application/smil',
  212. 'snd' => 'audio/basic',
  213. 'so' => 'application/octet-stream',
  214. 'svg' => 'image/svg+xml',
  215. 't' => 'application/x-troff',
  216. 'texi' => 'application/x-texinfo',
  217. 'texinfo' => 'application/x-texinfo',
  218. 'tif' => 'image/tiff',
  219. 'tiff' => 'image/tiff',
  220. 'tr' => 'application/x-troff',
  221. 'txt' => 'text/plain',
  222. 'vrml' => 'model/vrml',
  223. 'vxml' => 'application/voicexml+xml',
  224. 'webm' => 'video/webm',
  225. 'webp' => 'image/webp',
  226. 'wrl' => 'model/vrml',
  227. 'xht' => 'application/xhtml+xml',
  228. 'xhtml' => 'application/xhtml+xml',
  229. 'xml' => 'application/xml',
  230. 'xsl' => 'application/xml',
  231. 'xslt' => 'application/xslt+xml',
  232. 'xul' => 'application/vnd.mozilla.xul+xml',
  233. ];
  234. /**
  235. * 根据文件名,获取http协议header中的content-type应该填写的数据
  236. *
  237. * @param string $name 缺省名
  238. * @return string content-type
  239. */
  240. public static function getMimeByName($name)
  241. {
  242. $parts = explode('.', $name);
  243. if (count($parts) > 1) {
  244. $ext = strtolower(end($parts));
  245. if (isset(self::$mime_types[$ext])) {
  246. return self::$mime_types[$ext];
  247. }
  248. }
  249. return null;
  250. }
  251. }