Converts a file extension into a mime type.

@param string $ext

@return string|bool mime type string or false
487250
public function mimeFromExtension($ext)
    {
        $ext = strtolower($ext);
        if (array_key_exists($ext, self::$mime_types_and_extensions)) {
            return self::$mime_types_and_extensions[$ext];
        }

        return false;
    }
1049575
static function changeExtention($path, $ext)
    {
        $dir = dirname($path).'/';
        $f = self::fileInfo($path);
        return $dir.$f['base'].'.'.$ext;
    }
838089
private function checkExt($ext)
    {
        if (!empty($this->allowExts)) {
            return in_array(strtolower($ext), $this->allowExts, true);
        }
        return true;
    }
956542
public static function get_app_category($ext)
    {
        $ext = strtolower($ext);
        foreach (static::config()->get('app_categories') as $category => $exts) {
            if (in_array($ext, $exts)) {
                return $category;
            }
        }
        return false;
    }
1108403
public function acceptsMimeEncoding($ext)
    {
        if ($this->getAllowedMimeEncodings() && !in_array($ext, $this->getAllowedMimeEncodings())) {
            return false;
        }

        if ($this->getRejectedMimeEncodings() && in_array($ext, $this->getRejectedMimeEncodings())) {
            return false;
        }

        return true;
    }
237375
private static function get_mime_type($extension) {
		$mime_type = '';
		switch ($extension) {
			case 'htm' :
			case 'html': $mime_type = 'text/html';
			             break;

			case 'css' : $mime_type = 'text/css';
			             break;

			case 'ico' : $mime_type = 'image/x-icon';
			             break;

			case 'js'  : $mime_type = 'text/javascript';
			             break;

			case 'png' : $mime_type = 'image/png';
			             break;

			case 'gif' : $mime_type = 'image/gif';
			             break;

			case 'jpg' :
			case 'jpeg': $mime_type = 'image/jpeg';
			             break;

			case 'pdf' : $mime_type = 'application/pdf';
						 break;

			case 'txt' : $mime_type = 'text/plain';
						 break;

			case 'svg' : $mime_type = 'image/svg+xml';
						 break;

			default    : $mime_type = 'application/octet-stream';
		}

		return $mime_type;
	}
783150
public function findFile($file, $ext = '')
    {
        $paths = clone $this->getPaths();

        $file = str_replace('.', '/', $file);

        $ext = $ext ? '.' . trim($ext, '.') : '';

        foreach ($paths as $path) {
            $filePath = $path . '/' . $file . $ext;

            if (is_file($filePath)) {
                return realpath($filePath);
            }
        }

        return null;
    }
575228
private function checkAllowedTypes($ext = ''){

            $allowedTypes = $this->getAllowedExt();

            if ('*' === $allowedTypes) {
                return true;
            }else{

              if(is_string($allowedTypes))
              {
                  $allowedTypes = (array) $allowedTypes;
              }

                foreach($allowedTypes as $type)
                {

                    if($type === $ext)
                    {
                      return true;
                    }else{
                        continue;
                    }
                }
            }
            return false;
        }
204673
function get_type($ext)
    {
        $ext = strtolower($ext);
        // get position of last dot
        $dot_pos = strrpos($ext, '.');
        if ($dot_pos !== false) $ext = substr($ext, $dot_pos+1);
        if (($ext != '') && isset($this->mime_types[$ext])) return $this->mime_types[$ext];
        return false;
    }
1222396
public static function getMediaTypeFromFileContent(string $fileContent): string
    {
        $fileInfo = new \finfo(FILEINFO_MIME);
        $mediaType = self::trimMediaType($fileInfo->buffer($fileContent));
        return isset(self::$mediaTypeToFileExtension[$mediaType]) ? $mediaType : 'application/octet-stream';
    }
835022
public static function guessMimeType($extension = '', $isFile = true)
    {
        if ($isFile) {
            $map = config('cripfilesys.mime.map');
            return isset($map[$extension]) ?
                $map[$extension] : 'text/plain';
        }

        return 'dir';
    }
299178
public function checkExt($ext)
    {
        if (strpos($ext, '.')) {
            $ext = pathinfo($ext, PATHINFO_EXTENSION);
        }
        if (strpos($this->allowedExts, $ext) === false) {
            return false;
        } else {
            return true;
        }
    }
45569
public static function getMimeType($ext) {
		$ext = strtolower($ext);
		$mimes = array('hqx' => 'application/mac-binhex40', 'cpt' => 'application/mac-compactpro', 'doc' => 'application/msword', 
			'bin' => 'application/macbinary', 'dms' => 'application/octet-stream', 'lha' => 'application/octet-stream', 
			'lzh' => 'application/octet-stream', 'exe' => 'application/octet-stream', 'class' => 'application/octet-stream', 
			'psd' => 'application/octet-stream', 'so' => 'application/octet-stream', 'sea' => 'application/octet-stream', 
			'dll' => 'application/octet-stream', 'oda' => 'application/oda', 'pdf' => 'application/pdf', 
			'ai' => 'application/postscript', 'eps' => 'application/postscript', 'ps' => 'application/postscript', 
			'smi' => 'application/smil', 'smil' => 'application/smil', 'mif' => 'application/vnd.mif', 
			'xls' => 'application/vnd.ms-excel', 'ppt' => 'application/vnd.ms-powerpoint', 'wbxml' => 'application/vnd.wap.wbxml', 
			'wmlc' => 'application/vnd.wap.wmlc', 'dcr' => 'application/x-director', 'dir' => 'application/x-director', 
			'dxr' => 'application/x-director', 'dvi' => 'application/x-dvi', 'gtar' => 'application/x-gtar', 
			'php' => 'application/x-httpd-php', 'php4' => 'application/x-httpd-php', 'php3' => 'application/x-httpd-php', 
			'phtml' => 'application/x-httpd-php', 'phps'  => 'application/x-httpd-php-source', 'js' => 'application/x-javascript', 
			'swf' => 'application/x-shockwave-flash', 'sit' => 'application/x-stuffit', 'tar' => 'application/x-tar', 
			'tgz' => 'application/x-tar', 'xhtml' => 'application/xhtml+xml', 'xht' => 'application/xhtml+xml', 'zip' => 'application/zip', 
			'mid' => 'audio/midi', 'midi' => 'audio/midi', 'mpga' => 'audio/mpeg', 'mp2' => 'audio/mpeg', 'mp3' => 'audio/mpeg', 
			'aif' => 'audio/x-aiff', 'aiff' => 'audio/x-aiff', 'aifc' => 'audio/x-aiff', 'ram' => 'audio/x-pn-realaudio', 
			'rm' => 'audio/x-pn-realaudio', 'rpm' => 'audio/x-pn-realaudio-plugin', 'ra' => 'audio/x-realaudio', 
			'rv' => 'video/vnd.rn-realvideo', 'wav' => 'audio/x-wav', 'bmp' => 'image/bmp', 'gif' => 'image/gif', 'jpeg' => 'image/jpeg', 
			'jpg' => 'image/jpeg', 'jpe' => 'image/jpeg', 'png' => 'image/png', 'tiff' => 'image/tiff', 'tif' => 'image/tiff', 
			'css' => 'text/css', 'html' => 'text/html', 'htm' => 'text/html', 'shtml' => 'text/html', 'txt' => 'text/plain', 
			'text' => 'text/plain', 'log' => 'text/plain', 'rtx' => 'text/richtext', 'rtf' => 'text/rtf', 'xml' => 'text/xml', 
			'xsl' => 'text/xml', 'mpeg' => 'video/mpeg', 'mpg' => 'video/mpeg', 'mpe' => 'video/mpeg', 'qt' => 'video/quicktime', 
			'mov' => 'video/quicktime', 'avi' => 'video/x-msvideo', 'movie' => 'video/x-sgi-movie', 'doc' => 'application/msword', 
			'word' => 'application/msword', 'xl' => 'application/excel', 'eml' => 'message/rfc822');
		return (!isset($mimes[$ext])) ? 'application/octet-stream' : $mimes[strtolower($ext)];
	}
836906
public function isSafe($ext, $mime)
    {
        $unsafeExtensions = $this->package->config('block.extensions');
        $unsafeMimes = $this->package->config('block.mimetypes');
        $mimeSearch = function ($mimeValue) use ($mime) {
            return preg_match($mimeValue, $mime);
        };

        if (in_array($ext, $unsafeExtensions)) {
            return false;
        }

        if (collect($unsafeMimes)->search($mimeSearch)) {
            return false;
        }

        return true;
    }
960450
public function getDirectory($name, $ext)
	{
		if ('' === $name = '/' . trim($name, '/.') . '/')
			return true;

		$type = $this->getTypeForExt($ext);

		foreach ($this->paths as $path)
		{
			$prefixes = isset($path['prefixes']) ? $path['prefixes'] : array();
			$prefix = isset($prefixes[$type]) ? $prefixes[$type] . '/' : '';
			
			foreach ($path['directories'] as $directory)
			{
				if (file_exists($directory) && is_dir($directory))
					return $directory;
			}
		}
		
		throw new Exception\DirectoryNotFound($name);
	}
720726
public static function get_mime_extensions($mimetype = null)
    {
        static $mime_types, $mime_extensions;

        // return cached data
        if (is_array($mime_types)) {
            return $mimetype ? $mime_types[$mimetype] : $mime_extensions;
        }

        // load mapping file
        $file_paths = array();

        if ($mime_types = rcube::get_instance()->config->get('mime_types')) {
            $file_paths[] = $mime_types;
        }

        // try common locations
        if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') {
            $file_paths[] = 'C:/xampp/apache/conf/mime.types.';
        }
        else {
            $file_paths[] = '/etc/mime.types';
            $file_paths[] = '/etc/httpd/mime.types';
            $file_paths[] = '/etc/httpd2/mime.types';
            $file_paths[] = '/etc/apache/mime.types';
            $file_paths[] = '/etc/apache2/mime.types';
            $file_paths[] = '/etc/nginx/mime.types';
            $file_paths[] = '/usr/local/etc/httpd/conf/mime.types';
            $file_paths[] = '/usr/local/etc/apache/conf/mime.types';
            $file_paths[] = '/usr/local/etc/apache24/mime.types';
        }

        foreach ($file_paths as $fp) {
            if (@is_readable($fp)) {
                $lines = file($fp, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
                break;
            }
        }

        $mime_types = $mime_extensions = array();
        $regex = "/([\w\+\-\.\/]+)\s+([\w\s]+)/i";
        foreach ((array)$lines as $line) {
             // skip comments or mime types w/o any extensions
            if ($line[0] == '#' || !preg_match($regex, $line, $matches))
                continue;

            $mime = $matches[1];
            foreach (explode(' ', $matches[2]) as $ext) {
                $ext = trim($ext);
                $mime_types[$mime][] = $ext;
                $mime_extensions[$ext] = $mime;
            }
        }

        // fallback to some well-known types most important for daily emails
        if (empty($mime_types)) {
            foreach (rcube::get_instance()->config->resolve_paths('mimetypes.php') as $fpath) {
                $mime_extensions = array_merge($mime_extensions, (array) @include($fpath));
            }

            foreach ($mime_extensions as $ext => $mime) {
                $mime_types[$mime][] = $ext;
            }
        }

        // Add some known aliases that aren't included by some mime.types (#1488891)
        // the order is important here so standard extensions have higher prio
        $aliases = array(
            'image/gif'      => array('gif'),
            'image/png'      => array('png'),
            'image/x-png'    => array('png'),
            'image/jpeg'     => array('jpg', 'jpeg', 'jpe'),
            'image/jpg'      => array('jpg', 'jpeg', 'jpe'),
            'image/pjpeg'    => array('jpg', 'jpeg', 'jpe'),
            'image/tiff'     => array('tif'),
            'message/rfc822' => array('eml'),
            'text/x-mail'    => array('eml'),
        );

        foreach ($aliases as $mime => $exts) {
            $mime_types[$mime] = array_unique(array_merge((array) $mime_types[$mime], $exts));

            foreach ($exts as $ext) {
                if (!isset($mime_extensions[$ext])) {
                    $mime_extensions[$ext] = $mime;
                }
            }
        }

        return $mimetype ? $mime_types[$mimetype] : $mime_extensions;
    }
1027356
protected function _compress($content, $ext) {
		$compress = $this->getConfig('compress');
		if ($compress === true) {
			// Native compressor only supports HTML right now
			if ($ext === 'html') {
				$Compressor = new Compressor();
				$content = $Compressor->compress($content);
			}
		} elseif (is_callable($compress)) {
			$content = $compress($content, $ext);
		} elseif ($compress) {
			$content = call_user_func($compress, $content, $ext);
		}

		return $content;
	}