Source code for /Users/Shared/www/vhosts/top-frog/public_html/script_src/files/MimeTypes.class.php

  1.  <?php
  2.   /**
  3.   * Simple repository of common file mime types
  4.   *
  5.   * updated 2007-08-30
  6.   * added method for retrieval of single type
  7.   * added docx and xlsx types, added simple pdf group type
  8.   */
  9.   class AP_File_MimeTypes
  10.   {
  11.   public $types;
  12.   public $groups;
  13.  
  14.   /**
  15.   * construct
  16.   *
  17.   * initialize our mime types and groups
  18.   */
  19.   public function __construct()
  20.   {
  21.   $this->types = array(
  22.   'ai' => 'application/postscript',
  23.   'aif' => 'audio/x-aiff',
  24.   'aiff' => 'audio/x-aiff',
  25.   'asf' => 'video/x-ms-asf',
  26.   'asx' => 'video/x-ms-asx',
  27.   'avi' => 'video/avi',
  28.   'bin' => 'application/octet-stream',
  29.   'bmp' => 'image/bmp',
  30.   'bz' => 'application/x-bzip',
  31.   'bz2' => 'application/x-bzip2',
  32.   'crt' => 'application/x-x509-ca-cert',
  33.   'css' => 'text/css',
  34.   'csv' => 'text/plain',
  35.   'doc' => 'application/msword',
  36.   'docx' => 'application/msword',
  37.   'dot' => 'application/msword',
  38.   'dxf' => 'application/dxf',
  39.   'eps' => 'application/postscript',
  40.   'gif' => 'image/gif',
  41.   'gz' => 'application/x-gzip',
  42.   'gzip' => 'application/x-gzip',
  43.   'htm' => 'text/html',
  44.   'html' => 'text/html',
  45.   'ico' => 'image/x-icon',
  46.   'jpg' => 'image/jpeg',
  47.   'jpe' => 'image/jpeg',
  48.   'jpeg' => 'image/jpeg',
  49.   'js' => 'text/javascript',
  50.   'm4a' => 'audio/mp4',
  51.   'mov' => 'video/quicktime',
  52.   'mp3' => 'audio/mpeg',
  53.   'mp4' => 'video/mp4',
  54.   'mpeg' => 'video/mpeg',
  55.   'mpg' => 'video/mpeg',
  56.   'pdf' => 'application/pdf',
  57.   'php' => 'text/plain',
  58.   'phps' => 'text/plain',
  59.   'png' => 'image/png',
  60.   'pot' => 'application/vnd.ms-powerpoint',
  61.   'ppa' => 'application/vnd.ms-powerpoint',
  62.   'pps' => 'application/vnd.ms-powerpoint',
  63.   'ppt' => 'application/vnd.ms-powerpoint',
  64.   'ps' => 'application/postscript',
  65.   'qt' => 'video/quicktime',
  66.   'ra' => 'audio/x-pn-realaudio',
  67.   'ram' => 'audio/x-pn-realaudio',
  68.   'rtf' => 'application/rtf',
  69.   'shtml' => 'text/html',
  70.   'sit' => 'application/x-stuffit',
  71.   'swf' => 'application/x-shockwave-flash',
  72.   'sql' => 'text/plain',
  73.   'tar' => 'application/x-tar',
  74.   'tgz' => 'application/x-compressed',
  75.   'tif' => 'image/tiff',
  76.   'tiff' => 'image/tiff',
  77.   'txt' => 'text/plain',
  78.   'wav' => 'audio/wav',
  79.   'wma' => 'audio/x-ms-wma',
  80.   'wmf' => 'windows/metafile',
  81.   'wmv' => 'video/x-ms-wmv',
  82.   'xls' => 'application/vnd.ms-excel',
  83.   'xlsx' => 'application/vnd.ms-excel',
  84.   'xlt' => 'application/vnd.ms-excel',
  85.   'z' => 'application/x-compressed',
  86.   'zip' => 'application/zip'
  87.   );
  88.  
  89.   $groups['office'] = array('csv','doc','dot','pdf','pot','pps','ppt','rtf','txt','xls');
  90.   $groups['image'] = array('ai','bmp','dxf','eps','gif','ico','jpg','jpe','jpeg','pdf','png','ps','swf','tif','tiff','wmf');
  91.   $groups['compressed'] = array('bin','bz','bz2','gz','sit','tar','tgz','z','zip');
  92.   $groups['video'] = array('asf','asx','avi','mov','mpg','mpeg','mp4','qt','ra','ram','swf','wmv');
  93.   $groups['audio'] = array('mp3','m4a','ra','ram','wav','wma');
  94.   $groups['web'] = array('css','gif','ico','jpg','jpeg','js','htm','html','pdf','php','phps','png','shtml','sql');
  95.   $groups['pdf'] = array('pdf');
  96.  
  97.   $this->groups = $groups;
  98.   }
  99.  
  100.   /**
  101.   * Return array of mime types
  102.   *
  103.   * @param string/bool $group_type
  104.   * @return array
  105.   */
  106.   public function getTypes($group_type=false)
  107.   {
  108.   if(!$group_type) { return $this->types; }
  109.   else
  110.   {
  111.   if(array_key_exists($group_type,$this->groups))
  112.   {
  113.   foreach($this->types as $key => $mt)
  114.   {
  115.   if(in_array($key,$this->groups[$group_type])) { $types[$key] = $mt; }
  116.   }
  117.   return $types;
  118.   }
  119.   else { return false; }
  120.   }
  121.   }
  122.  
  123.   /**
  124.   * Return a single type
  125.   *
  126.   */
  127.   public function getType($type)
  128.   {
  129.   if(array_key_exists($type,$this->groups)) { return $this->groups[$type]; }
  130.   else { return false; }
  131.   }
  132.  
  133.   /**
  134.   * Destruct
  135.   *
  136.   */
  137.   public function __destruct()
  138.   {
  139.   unset($this->groups,$this->types);
  140.   }
  141.  
  142.   }
  143.  
  144.  ?>