<?php

class mime_types {
  private static $mime_path;
  private static $mime_types = null;
  static function init(){
    self::$mime_path = $_SERVER['mime_types_path'];
    if(!self::$mime_path) self::$mime_path = "/etc/httpd/conf/mime.types";
    if(!is_file(self::$mime_path))
        throw new Exception("mime_type, invalid configuration, chk env mime_types_path");
  }

  private static function build_cache(){
    self::$mime_types = array();
    foreach(file(self::$mime_path) as $line) {
        $c = strpos($line, "#");
        if($c!==false) $line = substr($line, 0, $c);
        $line = trim($line);
        if(!$line)continue;
        $line = preg_split("#\s+#", $line);
        if(count($line)==1)continue;
        $content_type = array_shift($line);
        foreach($line as $ext)
            self::$mime_types[$ext] = $content_type;
    }
  }

  static function get_content_type($ext){
    if(!is_null(self::$mime_types))
        return self::$mime_types[$ext];
    
    self::build_cache();
    return self::$mime_types[$ext];
  }
}

<?php

class mime_types {
  private static $mime_path;
  private static $mime_types = null;
  static function init(){
    self::$mime_path = $_SERVER['mime_types_path'];
    if(!self::$mime_path) self::$mime_path = "/etc/httpd/conf/mime.types";
    if(!is_file(self::$mime_path))
        throw new Exception("mime_type, invalid configuration, chk env mime_types_path");
  }

  private static function build_cache(){
    self::$mime_types = array();
    foreach(file(self::$mime_path) as $line) {
        $c = strpos($line, "#");
        if($c!==false) $line = substr($line, 0, $c);
        $line = trim($line);
        if(!$line)continue;
        $line = preg_split("#\s+#", $line);
        if(count($line)==1)continue;
        $content_type = array_shift($line);
        foreach($line as $ext)
            self::$mime_types[$ext] = $content_type;
    }
  }

  static function get_ext($content_type){
    if(is_null(self::$mime_types))
      self::build_cache();

    $tmp = array_flip(self::$mime_types);

    return $tmp[$content_type];
  }

  static function get_content_type($ext){
    if(!is_null(self::$mime_types))
        return self::$mime_types[$ext];

    self::build_cache();
    return self::$mime_types[$ext];
  }
}

Add fonction for retrieve ext from contenttype
Add fonction for retrieve ext from contenttype

git-svn-id: 4cd2d1688610a87757c9f4de95975a674329c79f@1682 b8ca103b-dd03-488c-9448-c80b36131af2
