php 根据文件后缀后获取mine类型的简单示例

前端之家收集整理的这篇文章主要介绍了php 根据文件后缀后获取mine类型的简单示例前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
感兴趣的小伙伴,下面一起跟随编程之家 jb51.cc的小编来看看吧。
经测试代码如下:
  1. /**
  2. * 根据文件后缀获取其mine类型
  3. *
  4. * @author 编程之家 jb51.cc jb51.cc
  5. * @param string $extension
  6. * @return string
  7. */
  8. function get_mimetype($extension) {
  9. $ct['htm'] = 'text/html';
  10. $ct['html'] = 'text/html';
  11. $ct['txt'] = 'text/plain';
  12. $ct['asc'] = 'text/plain';
  13. $ct['bmp'] = 'image/bmp';
  14. $ct['gif'] = 'image/gif';
  15. $ct['jpeg'] = 'image/jpeg';
  16. $ct['jpg'] = 'image/jpeg';
  17. $ct['jpe'] = 'image/jpeg';
  18. $ct['png'] = 'image/png';
  19. $ct['ico'] = 'image/vnd.microsoft.icon';
  20. $ct['mpeg'] = 'video/mpeg';
  21. $ct['mpg'] = 'video/mpeg';
  22. $ct['mpe'] = 'video/mpeg';
  23. $ct['qt'] = 'video/quicktime';
  24. $ct['mov'] = 'video/quicktime';
  25. $ct['avi'] = 'video/x-msvideo';
  26. $ct['wmv'] = 'video/x-ms-wmv';
  27. $ct['mp2'] = 'audio/mpeg';
  28. $ct['mp3'] = 'audio/mpeg';
  29. $ct['rm'] = 'audio/x-pn-realaudio';
  30. $ct['ram'] = 'audio/x-pn-realaudio';
  31. $ct['rpm'] = 'audio/x-pn-realaudio-plugin';
  32. $ct['ra'] = 'audio/x-realaudio';
  33. $ct['wav'] = 'audio/x-wav';
  34. $ct['css'] = 'text/css';
  35. $ct['zip'] = 'application/zip';
  36. $ct['pdf'] = 'application/pdf';
  37. $ct['doc'] = 'application/msword';
  38. $ct['bin'] = 'application/octet-stream';
  39. $ct['exe'] = 'application/octet-stream';
  40. $ct['class'] = 'application/octet-stream';
  41. $ct['dll'] = 'application/octet-stream';
  42. $ct['xls'] = 'application/vnd.ms-excel';
  43. $ct['ppt'] = 'application/vnd.ms-powerpoint';
  44. $ct['wbxml'] = 'application/vnd.wap.wbxml';
  45. $ct['wmlc'] = 'application/vnd.wap.wmlc';
  46. $ct['wmlsc'] = 'application/vnd.wap.wmlscriptc';
  47. $ct['dvi'] = 'application/x-dvi';
  48. $ct['spl'] = 'application/x-futuresplash';
  49. $ct['gtar'] = 'application/x-gtar';
  50. $ct['gzip'] = 'application/x-gzip';
  51. $ct['js'] = 'application/x-javascript';
  52. $ct['swf'] = 'application/x-shockwave-flash';
  53. $ct['tar'] = 'application/x-tar';
  54. $ct['xhtml'] = 'application/xhtml+xml';
  55. $ct['au'] = 'audio/basic';
  56. $ct['snd'] = 'audio/basic';
  57. $ct['midi'] = 'audio/midi';
  58. $ct['mid'] = 'audio/midi';
  59. $ct['m3u'] = 'audio/x-mpegurl';
  60. $ct['tiff'] = 'image/tiff';
  61. $ct['tif'] = 'image/tiff';
  62. $ct['rtf'] = 'text/rtf';
  63. $ct['wml'] = 'text/vnd.wap.wml';
  64. $ct['wmls'] = 'text/vnd.wap.wmlscript';
  65. $ct['xsl'] = 'text/xml';
  66. $ct['xml'] = 'text/xml';
  67. return isset($ct[strtolower($extension)]) ? $ct[strtolower($extension)] : 'text/html';
  68. }

猜你在找的PHP相关文章