Return the mimetype based on existing local file

@param string $filename Path to the file

@return string|bool
511782
public static function getMimeByLocalFile($filename, $default = 'application/octet-stream')
    {
        $type = false;

        // For local files we can detect type by the file content.
        if (!stream_is_local($filename) || !file_exists($filename)) {
            return false;
        }

        // Prefer using finfo if it exists.
        if (\extension_loaded('fileinfo')) {
            $finfo = finfo_open(FILEINFO_SYMLINK | FILEINFO_MIME_TYPE);
            $type = finfo_file($finfo, $filename);
            finfo_close($finfo);
        } else {
            // Fall back to use getimagesize() if it is available (not recommended, but better than nothing)
            $info = @getimagesize($filename);
            if ($info) {
                $type = $info['mime'];
            }
        }

        return $type ?: static::getMimeByFilename($filename, $default);
    }
298790
private function getLocalFileHash($filename)
        {
                $path = $this->phpids_base . $filename;
                if (file_exists($path)) {
                        return sha1_file($path);
                } else {
                        return false;
                }
        }
641238
public function getMime($filename)
    {
        switch (substr($filename, -3)) {
            case "css":
                $mime = "text/css";
                break;
            case ".js":
                $mime = "text/javascript";
                break;
            default:
                $mime = (new \finfo(FILEINFO_MIME_TYPE))->file($filename);

        }

        return $mime;
    }
1221855
private static function lookupContentType($filename) {
    foreach ($_FILES as $file) {
      if ($file['tmp_name'] == $filename) {
        return $file['type'] ?: static::DEFAULT_CONTENT_TYPE;
      }
    }
    return static::DEFAULT_CONTENT_TYPE;
  }
1221620
public function getFileResource($fileName)
    {
        if (!in_array($fileName, $this->files, true))
            return false;

        return $this->archive->getFileResource($fileName);
    }
1271678
public static function mimetype($file)
    {
        if (!function_exists('finfo_open'))
            return false;
        $finfo = finfo_open(FILEINFO_MIME_TYPE);
        $mimetype = finfo_file($finfo, $file);
        finfo_close($finfo);
        return $mimetype;
    }
174804
public function getFileResource($fileName)
    {
        $Location = array_search($fileName, $this->files, true);
        if (!isset($this->filesData[$fileName])) return false;
        $data = $this->filesData[$fileName];
        $Location_Real = $Location * $this->blockSize;
        if ($this->iso->Seek($Location_Real, SEEK_SET) === false)
            return false;

        $resource = fopen('php://temp', 'r+');
        fwrite($resource, $this->iso->Read($data['size']));
        rewind($resource);
        return $resource;
    }
907332
protected static function getMimetypeFromLocalFilePath($filePath) {
		$mimetype = getMimeType($filePath);
		if( $mimetype !== 'text/plain' ) {
			return $mimetype;
		}
		return static::getMimetypeFromExtension(pathinfo($filePath, PATHINFO_EXTENSION));
	}
1114614
protected function getMimeType($originalName)
    {
        $mimeType = (string) $this->request->header('content-type');
        if (empty($mimeType) === true) {
            $mimeType = $this->files->mimeType($originalName);
        }

        return $mimeType;
    }
647061
public function getMime($filename): string {
        $info = $this->_getApi()->getObject([
            'Bucket' => $this->_config['bucket'],
            'Key' => $this->_getUri($filename),
        ]);

        if (f\prop('ContentType', $info)) {
            return $info['ContentType'];
        }
        throw new Exception("Could not retrieve mime type of {$filename}.");
    }
52725
public static function guessMimeType($filename, $default = 'application/octed-stream')
    {
        $guesser = new FileExtMimeTypeGuesser();

        $mime = $guesser->guess($filename);
        if (null === $mime) {
            try {
                $mime = MimeTypeGuesser::getInstance()->guess($filename);
            } catch (FileNotFoundException $ex) {
                // dont care
            }
        }

        return null === $mime ? $default : $mime;
    }
484205
public function getMimeType()
    {
        try {
            return $this->mimeType ?: $this->files->mimeType($this->name);
        } catch (ErrorException $e) {
            return;
        }
    }
627409
public static function mimeContentType($filename) {
        static $mime_types = [
            'html'    => 'text/html;charset=UTF-8',
            'htm'     => 'text/html;charset=UTF-8',
            'shtml'   => 'text/html;charset=UTF-8',
            'css'     => 'text/css',
            'xml'     => 'text/xml',
            'gif'     => 'image/gif',
            'jpeg'    => 'image/jpeg',
            'jpg'     => 'image/jpeg',
            'js'      => 'application/javascript',
            'atom'    => 'application/atom+xml',
            'rss'     => 'application/rss+xml',
            'mml'     => 'text/mathml',
            'txt'     => 'text/plain;charset=UTF-8',
            'jad'     => 'text/vnd.sun.j2me.app-descriptor',
            'wml'     => 'text/vnd.wap.wml',
            'htc'     => 'text/x-component',
            'png'     => 'image/png',
            'svg'     => 'image/svg+xml',
            'svgz'    => 'image/svg+xml',
            'tif'     => 'image/tiff',
            'tiff'    => 'image/tiff',
            'wbmp'    => 'image/vnd.wap.wbmp',
            'webp'    => 'image/webp',
            'ico'     => 'image/x-icon',
            'jng'     => 'image/x-jng',
            'bmp'     => 'image/x-ms-bmp',
            'woff'    => 'font/woff',
            'woff2'   => 'font/woff2',
            'jar'     => 'application/java-archive',
            'war'     => 'application/java-archive',
            'ear'     => 'application/java-archive',
            'json'    => 'application/json',
            'hqx'     => 'application/mac-binhex40',
            'doc'     => 'application/msword',
            'pdf'     => 'application/pdf',
            'ps'      => 'application/postscript',
            'eps'     => 'application/postscript',
            'ai'      => 'application/postscript',
            'rtf'     => 'application/rtf',
            'm3u8'    => 'application/vnd.apple.mpegurl',
            'kml'     => 'application/vnd.google-earth.kml+xml',
            'kmz'     => 'application/vnd.google-earth.kmz',
            'xls'     => 'application/vnd.ms-excel',
            'eot'     => 'application/vnd.ms-fontobject',
            'ppt'     => 'application/vnd.ms-powerpoint',
            'odg'     => 'application/vnd.oasis.opendocument.graphics',
            'odp'     => 'application/vnd.oasis.opendocument.presentation',
            'ods'     => 'application/vnd.oasis.opendocument.spreadsheet',
            'odt'     => 'application/vnd.oasis.opendocument.text',
            'pptx'    => 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
            'xlsx'    => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
            'docx'    => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
            'wmlc'    => 'application/vnd.wap.wmlc',
            '7z'      => 'application/x-7z-compressed',
            'cco'     => 'application/x-cocoa',
            'jardiff' => 'application/x-java-archive-diff',
            'jnlp'    => 'application/x-java-jnlp-file',
            'run'     => 'application/x-makeself',
            'pl'      => 'application/x-perl',
            'pm'      => 'application/x-perl',
            'prc'     => 'application/x-pilot',
            'pdb'     => 'application/x-pilot',
            'rar'     => 'application/x-rar-compressed',
            'rpm'     => 'application/x-redhat-package-manager',
            'sea'     => 'application/x-sea',
            'swf'     => 'application/x-shockwave-flash',
            'sit'     => 'application/x-stuffit',
            'tcl'     => 'application/x-tcl',
            'tk'      => 'application/x-tcl',
            'der'     => 'application/x-x509-ca-cert',
            'pem'     => 'application/x-x509-ca-cert',
            'crt'     => 'application/x-x509-ca-cert',
            'xpi'     => 'application/x-xpinstall',
            'xhtml'   => 'application/xhtml+xml;charset=UTF-8',
            'xspf'    => 'application/xspf+xml',
            'zip'     => 'application/zip',
            'bin'     => 'application/octet-stream',
            'exe'     => 'application/octet-stream',
            'dll'     => 'application/octet-stream',
            'deb'     => 'application/octet-stream',
            'dmg'     => 'application/octet-stream',
            'iso'     => 'application/octet-stream',
            'img'     => 'application/octet-stream',
            'msi'     => 'application/octet-stream',
            'msp'     => 'application/octet-stream',
            'msm'     => 'application/octet-stream',
            'mid'     => 'audio/midi',
            'midi'    => 'audio/midi',
            'kar'     => 'audio/midi',
            'mp3'     => 'audio/mpeg',
            'ogg'     => 'audio/ogg',
            'm4a'     => 'audio/x-m4a',
            'ra'      => 'audio/x-realaudio',
            '3gpp'    => 'video/3gpp',
            '3gp'     => 'video/3gpp',
            'ts'      => 'video/mp2t',
            'mp4'     => 'video/mp4',
            'mpeg'    => 'video/mpeg',
            'mpg'     => 'video/mpeg',
            'mov'     => 'video/quicktime',
            'webm'    => 'video/webm',
            'flv'     => 'video/x-flv',
            'm4v'     => 'video/x-m4v',
            'mng'     => 'video/x-mng',
            'asx'     => 'video/x-ms-asf',
            'asf'     => 'video/x-ms-asf',
            'wmv'     => 'video/x-ms-wmv',
            'avi'     => 'video/x-msvideo'
        ];
        $chks = explode('.', $filename);
        $ext  = strtolower(array_pop($chks));
        if (array_key_exists($ext, $mime_types)) {
            return $mime_types[ $ext ];
        } else if (is_file($filename) && function_exists('finfo_open')) {
            $finfo    = finfo_open(FILEINFO_MIME);
            $mimetype = finfo_file($finfo, $filename);
            finfo_close($finfo);

            return $mimetype;
        } else {
            return 'application/octet-stream';
        }
    }
1133713
public static function filenameToType($filename)
    {
        // In case the path is a URL, strip any query string before getting extension
        $qpos = strpos($filename, '?');
        if ($qpos !== false) {
            $filename = substr($filename, 0, $qpos);
        }
        $pathinfo = self::mb_pathinfo($filename);
        return self::_mime_types($pathinfo['extension']);
    }
682781
public static function getGeoIPDatabaseTypeFromFilename($filename)
    {
        foreach (self::$dbNames as $key => $names) {
            foreach ($names as $name) {
                if ($name === $filename) {
                    return $key;
                }
            }
        }
        return false;
    }
44152
public static function getMimeType($filePath)
    {
        $fInfo = finfo_open(FILEINFO_MIME_TYPE);
        $mime  = finfo_file($fInfo, $filePath);
        finfo_close($fInfo);

        return $mime;
    }
1335689
public static function getMimeType($tmpName) {

    $finfo = finfo_open(FILEINFO_MIME_TYPE);
    $mimeType = finfo_file($finfo, $tmpName);

    return $mimeType;
  }