Get mime-type from file.
Checks extensions array first, then attempts to get mime-type using Finfo

@param  string $file Path to file
@return string       Mime-type
552113
public function getMimeTypeFromFile($file)
	{
		$extension = strtolower(pathinfo($file, PATHINFO_EXTENSION));
		if (array_key_exists($extension, $this->_alt_mime_types)) {
			return $this->_alt_mime_types[$extension];
		} else {
			return (new \Finfo(FILEINFO_MIME_TYPE))->file($file);
		}
	}
1275273
public static function getMime($file)
    {
        $fileInfo = finfo_open(FILEINFO_MIME_TYPE);
        $mime = finfo_file($fileInfo, $file);

        return empty($mime) ? : $mime;
    }
366467
public function getMimeType()
	{
		$finfo = finfo_open(FILEINFO_MIME_TYPE);
		$mime = finfo_file($finfo, $this->path);
		finfo_close($finfo);

		return $mime;
	}
943487
public static function getType($extension) {
        foreach (self::$map as $mime => $exts) {
            if (in_array(strtolower($extension), $exts)) {
                return $mime;
            }
        }
        return null;
    }
616419
public static function get(
        $file
    ) {
        if (is_string($file)) {
            $file = new \SplFileInfo($file);
        }

        $extension = mb_strtolower($file->getExtension());
        if ('' === $extension) {
            return static::MIME_TYPE_IF_UNKNOWN;
        }

        if (array_key_exists($extension, static::$mimeTypes)) {
            return static::$mimeTypes[$extension];
        }

        if (function_exists('finfo_open') && $file->isFile()) {
            $path = $file->getPath();

            $fileInfo = finfo_open(FILEINFO_MIME);
            $mimeType = finfo_file($fileInfo, $path);
            finfo_close($fileInfo);

            return $mimeType;
        }

        return static::MIME_TYPE_IF_UNKNOWN;
    }
1367132
private function isAllowedFileType($file) {
	$path_parts = pathinfo($file);
	// if there is no extension AND no extension file are not allowed
	if(!isset($path_parts['extension']) && $this->config['security']['allowNoExtension'] == false) {
		return false;
	} else {
		return true;
	}
	$exts = array_map('strtolower', $this->config['security']['uploadRestrictions']);
	if($this->config['security']['uploadPolicy'] == 'DISALLOW_ALL') {
		if(!in_array(strtolower($path_parts['extension']), $exts))
			return false;
	}
	if($this->config['security']['uploadPolicy'] == 'ALLOW_ALL') {
		if(in_array(strtolower($path_parts['extension']), $exts))
			return false;
	}
	return true;
}
716494
private function setMimeType($file = '')
    {
        $ext = explode('.', $file);

        switch ($ext[count($ext) - 1]) {
            case 'jpeg':
                $this->_mimeType = 'image/jpeg';
                break;
            case 'jpg':
                $this->_mimeType = 'image/jpg';
                break;
            case 'gif':
                $this->_mimeType = 'image/gif';
                break;
            case 'png':
                $this->_mimeType = 'image/png';
                break;
            case 'pdf':
                $this->_mimeType = 'application/pdf';
                break;
            case 'txt':
                $this->_mimeType = 'text/plain';
                break;
            case 'jad':
                $this->_mimeType = 'text/vnd.sun.j2me.app-descriptor';
                break;
            case 'jar':
                $this->_mimeType = 'application/java-archive';
                break;
            case 'zip':
                $this->_mimeType = 'application/zip';
                break;
            case 'doc':
                $this->_mimeType = 'application/msword';
                break;
            case 'docx':
                $this->_mimeType = 'application/msword';
                break;
            case 'xls':
                $this->_mimeType = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
                break;
            case 'ppt':
                $this->_mimeType = 'application/vnd.ms-powerpoint';
                break;
            case 'wbmp':
                $this->_mimeType = 'image/vnd.wap.wbmp';
                break;
            case 'wmlc':
                $this->_mimeType = 'application/vnd.wap.wmlc';
                break;
            case 'mp4s':
                $this->_mimeType = 'application/mp4';
                break;
            case 'ogg':
                $this->_mimeType = 'application/ogg';
                break;
            case 'pls':
                $this->_mimeType = 'application/pls+xml';
                break;
            case 'asf':
                $this->_mimeType = 'application/vnd.ms-asf';
                break;
            case 'swf':
                $this->_mimeType = 'application/x-shockwave-flash';
                break;
            case 'mp4':
                $this->_mimeType = 'video/mp4';
                break;
            case 'm4a':
                $this->_mimeType = 'audio/mp4';
                break;
            case 'm4p':
                $this->_mimeType = 'audio/mp4';
                break;
            case 'mp4a':
                $this->_mimeType = 'audio/mp4';
                break;
            case 'mp3':
                $this->_mimeType = 'audio/mpeg';
                break;
            case 'm3a':
                $this->_mimeType = 'audio/mpeg';
                break;
            case 'm2a':
                $this->_mimeType = 'audio/mpeg';
                break;
            case 'mp2a':
                $this->_mimeType = 'audio/mpeg';
                break;
            case 'mp2':
                $this->_mimeType = 'audio/mpeg';
                break;
            case 'mpga':
                $this->_mimeType = 'audio/mpeg';
                break;
            case 'wav':
                $this->_mimeType = 'audio/wav';
                break;
            case 'm3u':
                $this->_mimeType = 'audio/x-mpegurl';
                break;
            case 'bmp':
                $this->_mimeType = 'image/bmp';
                break;
            case 'ico':
                $this->_mimeType = 'image/x-icon';
                break;
            case '3gp':
                $this->_mimeType = 'video/3gpp';
                break;
            case '3g2':
                $this->_mimeType = 'video/3gpp2';
                break;
            case 'mp4v':
                $this->_mimeType = 'video/mp4';
                break;
            case 'mpg4':
                $this->_mimeType = 'video/mp4';
                break;
            case 'm2v':
                $this->_mimeType = 'video/mpeg';
                break;
            case 'm1v':
                $this->_mimeType = 'video/mpeg';
                break;
            case 'mpe':
                $this->_mimeType = 'video/mpeg';
                break;
            case 'mpeg':
                $this->_mimeType = 'video/mpeg';
                break;
            case 'mpg':
                $this->_mimeType = 'video/mpeg';
                break;
            case 'mov':
                $this->_mimeType = 'video/quicktime';
                break;
            case 'qt':
                $this->_mimeType = 'video/quicktime';
                break;
            case 'avi':
                $this->_mimeType = 'video/x-msvideo';
                break;
            case 'midi':
                $this->_mimeType = 'audio/midi';
                break;
            case 'mid':
                $this->_mimeType = 'audio/mid';
                break;
            case 'amr':
                $this->_mimeType = 'audio/amr';
                break;
            default:
                $this->_mimeType = 'application/force-download';
        }

        return true;
    }
157254
def _file_type(file):
    
    # %%%%%%%%%%%%%%%%%%%%%%%%%%%%% Verification of file type %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    if "." in file:  # File with known extension.
        file_type = file.split(".")[-1]
    else:  # File without known extension.
        file_type = magic.from_file(file, mime=True).split("/")[-1]

    return file_type
1308842
public static function getMimeType($filename)
	{
		$mime_types = static::getMimeTypes();
		
		$extension = pathinfo($filename, PATHINFO_EXTENSION);
    	$extension = strtolower($extension);
    	
		if (array_key_exists($extension, $mime_types)) {
            return $mime_types[$extension];
        } elseif (function_exists('finfo_open')) {
            $finfo = finfo_open(FILEINFO_MIME);
            $mimetype = finfo_file($finfo, $filename);
            finfo_close($finfo);
            return $mimetype;
        } 
        return 'application/octet-stream';
	}
806740
static public function getFileExt($file)
    {
        $s = strrchr($file, '.');
        if ($s === false)
        {
            return false;
        }
        return strtolower(trim(substr($s, 1)));
    }
301482
static function guessMimeType($fileName)
    {
        self::$map = include(__DIR__ . "/mime.types.php");
        $ext = pathinfo($fileName, PATHINFO_EXTENSION);
        return isset(self::$map[$ext]) ? self::$map[$ext] : 'application/octet-stream';
    }
140902
public static function __getMimeType(&$file)
        {
            $type = false;
            // Fileinfo documentation says fileinfo_open() will use the
            // MAGIC env var for the magic file
            if (extension_loaded('fileinfo') && isset($_ENV['MAGIC']) && ($finfo = finfo_open(FILEINFO_MIME, $_ENV['MAGIC'])) !== false) {
                if (($type = finfo_file($finfo, $file)) !== false) {
                    // Remove the charset and grab the last content-type
                    $type = explode(' ', repl('; charset=', ';charset=', $type));
                    $type = array_pop($type);
                    $type = explode(';', $type);
                    $type = trim(array_shift($type));
                }
                finfo_close($finfo);

            // If anyone is still using mime_content_type()
            } elseif (function_exists('mime_content_type')) {
                $type = trim(mime_content_type($file));
            }

            if ($type !== false && strlen($type) > 0) {
                return $type;
            }

            // Otherwise do it the old fashioned way
            static $exts = array(
                'jpg' => 'image/jpeg', 'gif' => 'image/gif', 'png' => 'image/png',
                'tif' => 'image/tiff', 'tiff' => 'image/tiff', 'ico' => 'image/x-icon',
                'swf' => 'application/x-shockwave-flash', 'pdf' => 'application/pdf',
                'zip' => 'application/zip', 'gz' => 'application/x-gzip',
                'tar' => 'application/x-tar', 'bz' => 'application/x-bzip',
                'bz2' => 'application/x-bzip2', 'txt' => 'text/plain',
                'asc' => 'text/plain', 'htm' => 'text/html', 'html' => 'text/html',
                'css' => 'text/css', 'js' => 'text/javascript',
                'xml' => 'text/xml', 'xsl' => 'application/xsl+xml',
                'ogg' => 'application/ogg', 'mp3' => 'audio/mpeg', 'wav' => 'audio/x-wav',
                'avi' => 'video/x-msvideo', 'mpg' => 'video/mpeg', 'mpeg' => 'video/mpeg',
                'mov' => 'video/quicktime', 'flv' => 'video/x-flv', 'php' => 'text/x-php'
            );

            $ext = Inflector::lower(pathInfo($file, PATHINFO_EXTENSION));

            return isset($exts[$ext]) ? $exts[$ext] : 'application/octet-stream';
        }
1098968
public function getFileContent($file)
    {
        // we can continue only when given file is really file and not a directory
        if ($this->fileInfo->getIsFile()) {
            $className = 'TeaminmediasPluswerk\KeSearch\Indexer\Filetypes\\' . ucfirst($this->fileInfo->getExtension());

            // check if class exists
            if (class_exists($className)) {
                // make instance
                $fileObj = GeneralUtility::makeInstance($className, $this->pObj);

                // check if new object has interface implemented
                if ($fileObj instanceof FileIndexerInterface) {
                    // Do the check if a file has already been indexed at this early point in order
                    // to skip the time expensive "get content" process which includes calls to external tools
                    // fetch the file content directly from the index
                    $fileContent = $this->getFileContentFromIndex($this->getUniqueHashForFile());

                    // if there's no matching index entry, we execute the  "get file content" method of our new object
                    if (!$fileContent) {
                        $fileContent = $fileObj->getContent($file);
                        $this->addError($fileObj->getErrors());
                    }

                    // remove line breaks from content in order to identify
                    // additional content (which will have trailing linebreaks)
                    $fileContent = str_replace("\n", ' ', $fileContent);

                    return $fileContent;
                } else {
                    return false;
                }
            } else {
                // if no indexer for this type of file exists, we do a fallback:
                // we return an empty content. Doing this at least the FAL metadata
                // can be indexed. So this makes only sense when using FAL.
                if ($this->pObj->indexerConfig['fal_storage'] > 0) {
                    return '';
                } else {
                    $errorMessage = 'No indexer for this type of file. (class ' . $className . ' does not exist).';
                    $this->pObj->logger->error($errorMessage);
                    $this->addError($errorMessage);
                    return false;
                }
            }
        } else {
            $errorMessage = $file . ' is not a file.';
            $this->pObj->logger->error($errorMessage);
            $this->addError($errorMessage);
            return false;
        }
    }
1240231
protected static function attachment_mime($file)
	{
		static $mimes = false;

		if ( ! $mimes)
		{
			$mimes = \Config::load('mimes');
		}

		$ext = pathinfo($file, PATHINFO_EXTENSION);

		$mime = \Arr::get($mimes, $ext, 'application/octet-stream');
		is_array($mime) and $mime = reset($mime);

		return $mime;
	}
292912
private function _getExtension($file = null)
	{
		if (!is_null($file))
		{
			$dot = strrpos($file, '.') + 1;

			return strtolower(substr($file, $dot));
		}

		return '##INVALID_FILE##';
	}
497023
public static function getExtension($file){

		$file = trim($file);
		$extension = strtolower(substr(strrchr($file, '.'), 1));

		if($extension == $file){

			return '';
		}
		else{

			return $extension;
		}
	}
596000
public static function get_mime_type($filename)
    {
        // If the finfo module is compiled into PHP, use it.
        $path = BASE_PATH . DIRECTORY_SEPARATOR . $filename;
        if (class_exists('finfo') && file_exists($path)) {
            $finfo = new finfo(FILEINFO_MIME_TYPE);
            return $finfo->file($path);
        }

        // Fallback to use the list from the HTTP.yml configuration and rely on the file extension
        // to get the file mime-type
        $ext = strtolower(File::get_file_extension($filename));
        // Get the mime-types
        $mimeTypes = HTTP::config()->uninherited('MimeTypes');

        // The mime type doesn't exist
        if (!isset($mimeTypes[$ext])) {
            return 'application/unknown';
        }

        return $mimeTypes[$ext];
    }