/*!
\static
Finds the MIME type for the url \a $url by examining the url itself (not the content) and returns it.
If \a $returnDefault is set to \c true then it will always return a MIME structure,
if not it will return \c false if none were found.
164991
static function findByURL( $url, $returnDefault = true )
    {
        $instance = eZMimeType::instance();

        $file = $url;
        $dirPosition = strrpos( $url, '/' );
        if ( $dirPosition !== false )
            $file = substr( $url, $dirPosition + 1 );
        $suffixPosition = strrpos( $file, '.' );
        $suffix = false;
        $prefix = false;
        $mimeName = false;
        if ( $suffixPosition !== false )
        {
            $suffix = strtolower( substr( $file, $suffixPosition + 1 ) );
            if ( $suffix )
            {
                $subURL = substr( $file, 0, $suffixPosition );
                $suffixList =& $instance->SuffixList;
                if ( array_key_exists( $suffix, $suffixList ) )
                {
                    $mimeName = $suffixList[$suffix];
                }
            }
            if ( !$mimeName )
            {
                $prefixPosition = strpos( $file, '.' );
                if ( $prefixPosition !== false )
                {
                    $prefix = strtolower( substr( $file, 0, $prefixPosition ) );
                }
                if ( $prefix )
                {
                    $subURL = substr( $file, $suffixPosition + 1 );
                    $prefixList =& $instance->PrefixList;
                    if ( array_key_exists( $prefix, $prefixList ) )
                    {
                        $mimeName = $prefixList[$prefix];
                    }
                }
            }
            if ( $mimeName )
            {
                $mimeList =& $instance->MIMEList;
                if ( array_key_exists( $mimeName, $mimeList ) )
                {
                    $lastDirPosition = strrpos( $url, '/' );
                    $filename = $url;
                    $dirpath = false;
                    if ( $lastDirPosition !== false )
                    {
                        $filename = substr( $url, $lastDirPosition + 1 );
                        $dirpath = substr( $url, 0, $lastDirPosition );
                    }
                    $lastDirPosition = strrpos( $subURL, '/' );
                    $basename = $subURL;
                    if ( $lastDirPosition !== false )
                        $basename = substr( $subURL, $lastDirPosition + 1 );
                    $mime = $mimeList[$mimeName];
                    $mime['name'] = $mimeName;
                    $mime['url'] = $url;
                    $mime['filename'] = $filename;
                    $mime['dirpath'] = $dirpath;
                    $mime['basename'] = $basename;
                    $mime['suffix'] = $suffix;
                    $mime['prefix'] = $prefix;
                    $mime['is_valid'] = true;
                    return $mime;
                }
            }
        }
        return eZMimeType::defaultValue( $url, $returnDefault );
    }
541298
protected function mimeType() {

		$mime_type = get_post_mime_type( $this->post );

		if ( ! $mime_type ) {
			$mime_type = $this->raw( 'mime_type' );
		}

		return $mime_type ? esc_html( $mime_type ) : '';
	}
1353756
static function _fetchURL($url)
    {
        if (self::$disable_url_fetch) {
            return false;
        }

        $parts = parse_url($url);
        $data = '';
        switch ($parts['scheme']) {
            case 'http':
                $fsock = @fsockopen($parts['host'], isset($parts['port']) ? $parts['port'] : 80);
                if (!$fsock) {
                    return false;
                }
                fputs($fsock, "GET $parts[path] HTTP/1.0\r\n");
                fputs($fsock, "Host: $parts[host]\r\n\r\n");
                $line = fgets($fsock, 1024);
                if (strlen($line) < 3) {
                    return false;
                }
                preg_match('#HTTP/1.\d (\d{3})#', $line, $temp);
                if ($temp[1] != '200') {
                    return false;
                }

                // skip the rest of the headers in the http response
                while (!feof($fsock) && fgets($fsock, 1024) != "\r\n") {
                }

                while (!feof($fsock)) {
                    $data.= fread($fsock, 1024);
                }

                break;
            //case 'ftp':
            //case 'ldap':
            //default:
        }

        return $data;
    }
430253
public function find($url)
    {
        $locale   = $this->getLocale();
        $fallback = $this->getLocaleFallback();
        $locator  = $this->getObject('translator.locator.factory')->createLocator($url);

        //Find translation based on the locale
        $result = $locator->setLocale($locale)->locate($url, $locale);

        //If no translations found, try using the fallback locale
        if(empty($result) && $fallback && $fallback != $locale) {
            $result = $locator->setLocale($fallback)->locate($url, $fallback);
        }

        return $result;
    }
685075
public function match($url)
    {
        if ($this->isString($url)) {
            $url = $this->url($url);
        } else {
            $url = StdObjectWrapper::isUrlObject($url) ? $url : $this->url('');
        }

        // get it from cache
        if (($result = $this->loadFromCache('match.' . $url->val())) !== false) {
            return $this->unserialize($result);
        }

        // try to match the url
        $result = $this->urlMatcher->match($url);

        // cache it
        $cacheResult = $this->isArray($result) ? $this->serialize($result) : $result;
        $this->saveToCache('match.' . $url->val(), $cacheResult);

        return $result;
    }
425803
static String _getMimeType(String uriOrPath) {
        String mime = MIME_MAP.get(__getExtension(uriOrPath));

        if (mime == null) {
            mime = DEFAULT_MIME;
        }

        return mime;
    }
430586
public static String getMimeTypeForFile(URL url) {
        if (url == null) {
            //The input url is null so we can't retrieve a mimetype, therefore we return null.
            return null;
        }
        String external = url.toExternalForm();
        if (external.indexOf('.') == -1) {
            return BINARY;
        } else {
            String ext = external.substring(external.lastIndexOf('.') + 1);
            String mime = KnownMimeTypes.getMimeTypeByExtension(ext);
            if (mime == null) {
                return BINARY;
            } else {
                return mime;
            }
        }
    }
1180997
public function mime()
    {
        if (!$this->exists()) {
            return false;
        }
        if (class_exists('finfo')) {
            $finfo = new finfo(FILEINFO_MIME);
            $type = $finfo->file($this->pwd());
            if (!$type) {
                return false;
            }
            list($type) = explode(';', $type);

            return $type;
        }
        if (function_exists('mime_content_type')) {
            return mime_content_type($this->pwd());
        }

        return false;
    }
544852
public function getMimetype()
	{
		if (is_null($this->mimetype)) {
			$ext = pathinfo($this->path, PATHINFO_EXTENSION);
			if ($ext === 'css') {
				return 'text/css';
			}
			if ($ext === 'js') {
				return 'text/javascript';
			}
			$guesser = MimeTypeGuesser::getInstance();
			$this->mimetype = $guesser->guess($this->getPath());
		}
		return $this->mimetype;
	}
1092651
static function findByName( $mimeName, $returnDefault = true )
    {
        $instance = eZMimeType::instance();
        $mimeList =& $instance->MIMEList;
        if ( isset( $mimeList[$mimeName] ) )
        {
            $mime = $mimeList[$mimeName];
            $mime['name'] = $mimeName;
            $mime['url'] = false;
            $mime['filename'] = false;
            $mime['dirpath'] = false;
            $mime['basename'] = false;
            $mime['suffix'] = false;
            if ( isset( $mime['suffixes'][0] ) )
                $mime['suffix'] = $mime['suffixes'][0];
            $mime['prefix'] = false;
            if ( isset( $mime['prefixes'][0] ) )
                $mime['prefix'] = $mime['prefixes'][0];
            $mime['is_valid'] = true;
            return $mime;
        }
        return eZMimeType::defaultValue( false, $returnDefault );
    }
302392
protected function _inspectContentType()
    {
        $mime = null;
        $charset = null;
        if (preg_match('/([-\w\/\.+]+)(;\s*?charset=(.+))?/i', $this->_headers['Content-Type']->value(), $matches)) {
            $mime = $mime ?: $matches[1];
            if (isset($matches[3])) {
                $charset = $charset ?: $matches[3];
            }
        }
        return [$mime, $charset];
    }
1255481
def detect_mimetype(file_data)
      if file_data.content_type.strip == "application/octet-stream"
        return File.mime_type?(file_data.original_filename)
      else
        return file_data.content_type
      end
    end
1023545
public function isMime()
    {
        $contentType = $this->getHeaderValue('Content-Type');
        $mimeVersion = $this->getHeaderValue('Mime-Version');
        return ($contentType !== null || $mimeVersion !== null);
    }
94494
public static function typeFromMimetype($mime)
    {
        foreach (static::types() as $type => $mimetypes) {
            if (array_search($mime, $mimetypes) !== false) {
                return $type;
            }
        }
    }
726355
public static String getMimeType(String url)
	{
	    String type = null;
	    String extension = MimeTypeMap.getFileExtensionFromUrl(url);
	    if (extension != null) {
	        MimeTypeMap mime = MimeTypeMap.getSingleton();
	        type = mime.getMimeTypeFromExtension(extension);
	    }
	    return type;
	}
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';
    }
1011856
public function getMimeType($path, $default = "application/octet-stream")
    {

        $finfo = finfo_open(FILEINFO_MIME_TYPE); // return mime type ala mimetype extension
        $fmtype = finfo_file($finfo, $path);

        finfo_close($finfo);

        return !empty($fmtype) ? $fmtype : $default;
    }