Get the general file type from a mime type.

This returns the beginning part (before the slash) of a mime type, giving a more general category of the file.

@param string $mime The mime type.
@return string The general file type.
519485
public static function get_file_type_from_mime($mime) {
		$validtypes = ['application', 'audio', 'image', 'message', 'multipart', 'text', 'video'];

		if (mb_stripos($mime, '/') === false) {
			// Malformed mime type.
			return false;
		}

		$iparts = explode('/', $mime);
		if (count($iparts) !== 2) {
			// Malformed mime type.
			return false;
		}

		return (in_array($iparts[0], $validtypes, true)) ? $iparts[0] : false;
	}
604220
public function mimeType() {
        // if the type is known, return it
        if (!is_null($this->type)) {
            return $this->type;
        }
        
        // make sure the file is available to check
        $this->downloadFile();
        
        // get the file info
        $finfo = finfo_open(FILEINFO_MIME_TYPE);
        
        // get the MIME type of the file 
        $mime= finfo_file($finfo, $this->downloadFilePath());
        
        // clode the file info resource
        finfo_close($finfo);
        
        // store and return the file MIME type
        return $this->type = $mime;
    }
443797
public function mime($mime = null)
    {
        if (!func_num_args()) {
            return $this->_stream->mime();
        }
        $this->_stream->mime($mime);
        return $this;
    }
943487
public static function getType($extension) {
        foreach (self::$map as $mime => $exts) {
            if (in_array(strtolower($extension), $exts)) {
                return $mime;
            }
        }
        return null;
    }
339474
public function getMimeType($extension)
    {
        if (isset($this->mimeTypes['.'.strtolower($extension)])) {
            return $this->mimeTypes['.'.strtolower($extension)];
        }

        return 'text/plain';
    }
1294708
public static function getMimeType($file)
    {
        $finfo = finfo_open(FILEINFO_MIME_TYPE);
        $type = finfo_file($finfo, $file);
        finfo_close($finfo);

        return $type;
    }
510924
public static function getMimetype(string $file): string
    {
        $finfo = finfo_open(FILEINFO_MIME_TYPE); // return mime type ala mimetype extension
        $mimetype = finfo_file($finfo, $file);
        finfo_close($finfo);
        
        return $mimetype;
    }
227515
public static function getMimeTypeByFile(string $file)
    {
        if (!\is_file($file) || !\class_exists('\finfo', false)) {
            return null;
        }

        try {
            $finfo = new \finfo(FILEINFO_MIME_TYPE);

            return $finfo->file($file) ?: null;
            // @codeCoverageIgnoreStart
        } catch (\ErrorException $e) {
            // This is caused by an array to string conversion error.
            return null;
        }
    }
1344525
public static function detect_mime_type($path) {
		$handle = finfo_open(FILEINFO_MIME);
		$mime_type = finfo_file($handle, $path);

		if (strpos($mime_type, ';')) {
			$mime_type = preg_replace('/;.*/', ' ', $mime_type);
		}

		return trim($mime_type);
	}
1014310
protected static function getTypeFileExtList($file) {

		$info = pathinfo(strtolower($file));

		if(isset(self::$extensionToMime[$info['extension']])) {
			return self::$extensionToMime[$info['extension']];
		}
		else {
			return self::DEFAULT_MIME_TYPE;
		}

	}
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;
    }
1106432
public function mimeContentType($file)
    {
        $result = new \finfo();

        if (is_resource($result) === true) {
            return $result->file($filename, FILEINFO_MIME_TYPE);
        }

        return false;
    }
64169
public function fileMimeType($path)
    {
        $type = $this->mimeDetect->findType(strtolower(pathinfo($path, PATHINFO_EXTENSION)));
        if (!empty($type)) {
            return $type;
        }

        return 'unknown/type';
    }
1275273
public static function getMime($file)
    {
        $fileInfo = finfo_open(FILEINFO_MIME_TYPE);
        $mime = finfo_file($fileInfo, $file);

        return empty($mime) ? : $mime;
    }
484205
public function getMimeType()
    {
        try {
            return $this->mimeType ?: $this->files->mimeType($this->name);
        } catch (ErrorException $e) {
            return;
        }
    }
366467
public function getMimeType()
	{
		$finfo = finfo_open(FILEINFO_MIME_TYPE);
		$mime = finfo_file($finfo, $this->path);
		finfo_close($finfo);

		return $mime;
	}
1159492
public static function getFromFile($path)
    {
        if (!($path instanceof File))
            $path = new File($path);

        $ext = $path->getExtension();
        $path = $path->getFullPath();

        $type = new FileType($ext ?? "", "");
        if (empty($type->getMimeType()) && file_exists($path))
            $type->setMimeType(mime_content_type($path));

        return $type;
    }