• 售前

  • 售后

热门帖子
入门百科

PHP实现的获取文件mimes范例工具类示例

[复制链接]
随缘6872 显示全部楼层 发表于 2021-10-25 19:54:29 |阅读模式 打印 上一主题 下一主题
本文实例讲述了PHP实现的获取文件mimes范例工具类。分享给各人供各人参考,详细如下:
  1. <?php
  2. /*
  3. * Copyright 2010-2013 Amazon.com, Inc. or its affiliates. All Rights Reserved.
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License").
  6. * You may not use this file except in compliance with the License.
  7. * A copy of the License is located at
  8. *
  9. * http://aws.amazon.com/apache2.0
  10. *
  11. * or in the "license" file accompanying this file. This file is distributed
  12. * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
  13. * express or implied. See the License for the specific language governing
  14. * permissions and limitations under the License.
  15. */
  16. /*%******************************************************************************************%*/
  17. // CLASS
  18. /**
  19. * Simplifies the process of looking up the content-types for a variety of file extensions.
  20. *
  21. * @version 2010.07.20
  22. * @license See the included NOTICE.md file for more information.
  23. * @copyright See the included NOTICE.md file for more information.
  24. * @link http://aws.amazon.com/php/ PHP Developer Center
  25. */
  26. class CFMimeTypes
  27. {
  28.   /**
  29.    * Map of the extension-to-mime-types that we support.
  30.    */
  31.   public static $mime_types = array(
  32.     '3gp' => 'video/3gpp',
  33.     'ai' => 'application/postscript',
  34.     'aif' => 'audio/x-aiff',
  35.     'aifc' => 'audio/x-aiff',
  36.     'aiff' => 'audio/x-aiff',
  37.     'asc' => 'text/plain',
  38.     'atom' => 'application/atom+xml',
  39.     'au' => 'audio/basic',
  40.     'avi' => 'video/x-msvideo',
  41.     'bcpio' => 'application/x-bcpio',
  42.     'bin' => 'application/octet-stream',
  43.     'bmp' => 'image/bmp',
  44.     'cdf' => 'application/x-netcdf',
  45.     'cgm' => 'image/cgm',
  46.     'class' => 'application/octet-stream',
  47.     'cpio' => 'application/x-cpio',
  48.     'cpt' => 'application/mac-compactpro',
  49.     'csh' => 'application/x-csh',
  50.     'css' => 'text/css',
  51.     'dcr' => 'application/x-director',
  52.     'dif' => 'video/x-dv',
  53.     'dir' => 'application/x-director',
  54.     'djv' => 'image/vnd.djvu',
  55.     'djvu' => 'image/vnd.djvu',
  56.     'dll' => 'application/octet-stream',
  57.     'dmg' => 'application/octet-stream',
  58.     'dms' => 'application/octet-stream',
  59.     'doc' => 'application/msword',
  60.     'dtd' => 'application/xml-dtd',
  61.     'dv' => 'video/x-dv',
  62.     'dvi' => 'application/x-dvi',
  63.     'dxr' => 'application/x-director',
  64.     'eps' => 'application/postscript',
  65.     'etx' => 'text/x-setext',
  66.     'exe' => 'application/octet-stream',
  67.     'ez' => 'application/andrew-inset',
  68.     'flv' => 'video/x-flv',
  69.     'gif' => 'image/gif',
  70.     'gram' => 'application/srgs',
  71.     'grxml' => 'application/srgs+xml',
  72.     'gtar' => 'application/x-gtar',
  73.     'gz' => 'application/x-gzip',
  74.     'hdf' => 'application/x-hdf',
  75.     'hqx' => 'application/mac-binhex40',
  76.     'htm' => 'text/html',
  77.     'html' => 'text/html',
  78.     'ice' => 'x-conference/x-cooltalk',
  79.     'ico' => 'image/x-icon',
  80.     'ics' => 'text/calendar',
  81.     'ief' => 'image/ief',
  82.     'ifb' => 'text/calendar',
  83.     'iges' => 'model/iges',
  84.     'igs' => 'model/iges',
  85.     'jnlp' => 'application/x-java-jnlp-file',
  86.     'jp2' => 'image/jp2',
  87.     'jpe' => 'image/jpeg',
  88.     'jpeg' => 'image/jpeg',
  89.     'jpg' => 'image/jpeg',
  90.     'js' => 'application/x-javascript',
  91.     'kar' => 'audio/midi',
  92.     'latex' => 'application/x-latex',
  93.     'lha' => 'application/octet-stream',
  94.     'lzh' => 'application/octet-stream',
  95.     'm3u' => 'audio/x-mpegurl',
  96.     'm4a' => 'audio/mp4a-latm',
  97.     'm4p' => 'audio/mp4a-latm',
  98.     'm4u' => 'video/vnd.mpegurl',
  99.     'm4v' => 'video/x-m4v',
  100.     'mac' => 'image/x-macpaint',
  101.     'man' => 'application/x-troff-man',
  102.     'mathml' => 'application/mathml+xml',
  103.     'me' => 'application/x-troff-me',
  104.     'mesh' => 'model/mesh',
  105.     'mid' => 'audio/midi',
  106.     'midi' => 'audio/midi',
  107.     'mif' => 'application/vnd.mif',
  108.     'mov' => 'video/quicktime',
  109.     'movie' => 'video/x-sgi-movie',
  110.     'mp2' => 'audio/mpeg',
  111.     'mp3' => 'audio/mpeg',
  112.     'mp4' => 'video/mp4',
  113.     'mpe' => 'video/mpeg',
  114.     'mpeg' => 'video/mpeg',
  115.     'mpg' => 'video/mpeg',
  116.     'mpga' => 'audio/mpeg',
  117.     'ms' => 'application/x-troff-ms',
  118.     'msh' => 'model/mesh',
  119.     'mxu' => 'video/vnd.mpegurl',
  120.     'nc' => 'application/x-netcdf',
  121.     'oda' => 'application/oda',
  122.     'ogg' => 'application/ogg',
  123.     'ogv' => 'video/ogv',
  124.     'pbm' => 'image/x-portable-bitmap',
  125.     'pct' => 'image/pict',
  126.     'pdb' => 'chemical/x-pdb',
  127.     'pdf' => 'application/pdf',
  128.     'pgm' => 'image/x-portable-graymap',
  129.     'pgn' => 'application/x-chess-pgn',
  130.     'pic' => 'image/pict',
  131.     'pict' => 'image/pict',
  132.     'png' => 'image/png',
  133.     'pnm' => 'image/x-portable-anymap',
  134.     'pnt' => 'image/x-macpaint',
  135.     'pntg' => 'image/x-macpaint',
  136.     'ppm' => 'image/x-portable-pixmap',
  137.     'ppt' => 'application/vnd.ms-powerpoint',
  138.     'ps' => 'application/postscript',
  139.     'qt' => 'video/quicktime',
  140.     'qti' => 'image/x-quicktime',
  141.     'qtif' => 'image/x-quicktime',
  142.     'ra' => 'audio/x-pn-realaudio',
  143.     'ram' => 'audio/x-pn-realaudio',
  144.     'ras' => 'image/x-cmu-raster',
  145.     'rdf' => 'application/rdf+xml',
  146.     'rgb' => 'image/x-rgb',
  147.     'rm' => 'application/vnd.rn-realmedia',
  148.     'roff' => 'application/x-troff',
  149.     'rtf' => 'text/rtf',
  150.     'rtx' => 'text/richtext',
  151.     'sgm' => 'text/sgml',
  152.     'sgml' => 'text/sgml',
  153.     'sh' => 'application/x-sh',
  154.     'shar' => 'application/x-shar',
  155.     'silo' => 'model/mesh',
  156.     'sit' => 'application/x-stuffit',
  157.     'skd' => 'application/x-koan',
  158.     'skm' => 'application/x-koan',
  159.     'skp' => 'application/x-koan',
  160.     'skt' => 'application/x-koan',
  161.     'smi' => 'application/smil',
  162.     'smil' => 'application/smil',
  163.     'snd' => 'audio/basic',
  164.     'so' => 'application/octet-stream',
  165.     'spl' => 'application/x-futuresplash',
  166.     'src' => 'application/x-wais-source',
  167.     'sv4cpio' => 'application/x-sv4cpio',
  168.     'sv4crc' => 'application/x-sv4crc',
  169.     'svg' => 'image/svg+xml',
  170.     'swf' => 'application/x-shockwave-flash',
  171.     't' => 'application/x-troff',
  172.     'tar' => 'application/x-tar',
  173.     'tcl' => 'application/x-tcl',
  174.     'tex' => 'application/x-tex',
  175.     'texi' => 'application/x-texinfo',
  176.     'texinfo' => 'application/x-texinfo',
  177.     'tif' => 'image/tiff',
  178.     'tiff' => 'image/tiff',
  179.     'tr' => 'application/x-troff',
  180.     'tsv' => 'text/tab-separated-values',
  181.     'txt' => 'text/plain',
  182.     'ustar' => 'application/x-ustar',
  183.     'vcd' => 'application/x-cdlink',
  184.     'vrml' => 'model/vrml',
  185.     'vxml' => 'application/voicexml+xml',
  186.     'wav' => 'audio/x-wav',
  187.     'wbmp' => 'image/vnd.wap.wbmp',
  188.     'wbxml' => 'application/vnd.wap.wbxml',
  189.     'webm' => 'video/webm',
  190.     'wml' => 'text/vnd.wap.wml',
  191.     'wmlc' => 'application/vnd.wap.wmlc',
  192.     'wmls' => 'text/vnd.wap.wmlscript',
  193.     'wmlsc' => 'application/vnd.wap.wmlscriptc',
  194.     'wmv' => 'video/x-ms-wmv',
  195.     'wrl' => 'model/vrml',
  196.     'xbm' => 'image/x-xbitmap',
  197.     'xht' => 'application/xhtml+xml',
  198.     'xhtml' => 'application/xhtml+xml',
  199.     'xls' => 'application/vnd.ms-excel',
  200.     'xml' => 'application/xml',
  201.     'xpm' => 'image/x-xpixmap',
  202.     'xsl' => 'application/xml',
  203.     'xslt' => 'application/xslt+xml',
  204.     'xul' => 'application/vnd.mozilla.xul+xml',
  205.     'xwd' => 'image/x-xwindowdump',
  206.     'xyz' => 'chemical/x-xyz',
  207.     'zip' => 'application/zip',
  208.   );
  209.   /**
  210.    * Attempt to match the file extension to a known mime-type.
  211.    *
  212.    * @param string $ext (Required) The file extension to attempt to map.
  213.    * @return string The mime-type to use for the file extension.
  214.    */
  215.   public static function get_mimetype($ext)
  216.   {
  217.     $ext = strtolower($ext); // Make sure the passed in extension is lowercase
  218.     return isset(self::$mime_types[$ext]) ? self::$mime_types[$ext] : 'application/octet-stream';
  219.   }
  220. }
复制代码
更多关于PHP相干内容感兴趣的读者可查看本站专题:《php文件操纵总结》、《PHP常用遍历算法与技巧总结》、《PHP数据布局与算法教程》、《php程序设计算法总结》、《PHP数组(Array)操纵技巧大全》、《php字符串(string)用法总结》及《php常见数据库操纵技巧汇总》
渴望本文所述对各人PHP程序设计有所资助。

帖子地址: 

回复

使用道具 举报

分享
推广
火星云矿 | 预约S19Pro,享500抵1000!
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

草根技术分享(草根吧)是全球知名中文IT技术交流平台,创建于2021年,包含原创博客、精品问答、职业培训、技术社区、资源下载等产品服务,提供原创、优质、完整内容的专业IT技术开发社区。
  • 官方手机版

  • 微信公众号

  • 商务合作