获取文件扩展名

@since 0.0.1
@param {string} $mimetype 文件MIME type
@return {string}
18185
private function getExtension($mimetype) {
		if(preg_match('/^(image|audio|video)\/(.+)$/', $mimetype, $matches)) {
			$extension = $matches[2];
			if(in_array($extension, ['jpeg', 'pjpeg'])) {
				$extension = 'jpg';
			} else if(in_array($extension, ['mpeg4'])) {
				$extension = 'mp4';
			}

			return $extension;
		}

		return null;
	}
1251787
public function getExtension($mimetype)
	{
		$key = array_search($mimetype, $this->mimeTypes);

		if (!$key)
		{
			$key = '';
		}

		return $key;
	}
126976
public function getMimeType(): string
    {
        $mimes = new MimeTypes();

        $type = $mimes->getMimeType($this->getAttribute('extension'));

        return $type ?? 'unknown';
    }
532793
public function getMimeType(){
		if( function_exists( 'finfo_open' ) ){
			$magicFile	= ini_get( 'mime_magic.magicfile' );
//			$magicFile	= str_replace( "\\", "/", $magicFile );
//			$magicFile	= preg_replace( "@\.mime$@", "", $magicFile );
			$fileInfo	= finfo_open( FILEINFO_MIME_TYPE, $magicFile );
			$mimeType	= finfo_file( $fileInfo, realpath( $this->pathName ) );
			finfo_close( $fileInfo );
			return $mimeType;
		}
		else if( substr( PHP_OS, 0, 3 ) != "WIN" ){
			$command	= 'file -b --mime-type '.escapeshellarg( $this->pathName );
			return trim( exec( $command ) );
		}
		else if( function_exists( 'mime_content_type' ) ){
			if( $mimeType = mime_content_type( $this->pathName ) )
				return $mimeType;
		}
		throw new RuntimeException( 'PHP extension Fileinfo is missing' );
	}
153805
public function matchMimetypeExtension($mimetype, $extension)
    {
        $mime_extensions = self::$mimetypes_extensions;
        if (isset($mime_extensions[$extension]) && $mime_extensions[$extension] == $mimetype) {
            return true;
        }

        return false;
    }
390845
public static function getMimeType($filename) {
		if( function_exists('finfo_open') ) {
			$finfo = finfo_open(FILEINFO_MIME_TYPE);
			return finfo_file($finfo, $filename);
		}
		return mime_content_type($filename);
	}
1194716
public function setMimeType($mimeType) {
        if (isset(self::$mimeTypeMapping[$mimeType])) {
            // The mime type has a mapping, use that instead
            $mimeType = self::$mimeTypeMapping[$mimeType];
        }

        $this->mimeType = $mimeType;

        return $this;
    }
1362370
public function readPath($path, $mimeType = null)
    {
        return $this->schemaFactory()->create(
            $this->reader()->readPath($path, $mimeType)
        );
    }
1050555
public function getMimeType()
    {
        if ($this->isUploaded() && $this->mime_type === null) {
            $temp_file_name = $this->getTempFileName();
            if (file_exists($temp_file_name)) {
                if (extension_loaded('fileinfo')) {
                    // Use the fileinfo extension if available.
                    $finfo = $this->getFinfo();
                    $this->mime_type = explode(
                        ';',
                        $finfo->file($temp_file_name)
                    )[0];
                } elseif (function_exists('mime_content_type')) {
                    // Fall back to mime_content_type() if available.
                    $this->mime_type = mime_content_type($temp_file_name);
                }

                // No mime-detection functions, or mime-detection function
                // failed to detect the type. Default to
                // 'application/octet-stream'. Relying on HTTP headers could
                // be a security problem so we never fall back to that option.
                if ($this->mime_type == '') {
                    $this->mime_type = 'application/octet-stream';
                }
            } else {
                $this->mime_type = $this->file['type'];
            }
        }

        return $this->mime_type;
    }
75084
public function getExtensionFromMimeType($mimeType) {
        return isset($this->mimeTypeToExtension[$mimeType]) ? $this->mimeTypeToExtension[$mimeType] : null;
    }
416867
public static function for_mimetype($mimeType)
    {
        $classes = ClassInfo::subclassesFor(DataFormatter::class);
        array_shift($classes);
        $sortedClasses = [];
        foreach ($classes as $class) {
            $sortedClasses[$class] = Config::inst()->get($class, 'priority');
        }
        arsort($sortedClasses);
        foreach ($sortedClasses as $className => $priority) {
            $formatter = new $className();
            if (in_array($mimeType, $formatter->supportedMimeTypes())) {
                return $formatter;
            }
        }
    }
318117
public function type($mimeTypes) {
        $types = array();

        foreach ((array) $mimeTypes as $mimeType) {
            switch ($mimeType) {
                case 'application': $types += MimeType::getApplicationList(); break;
                case 'audio':       $types += MimeType::getAudioList(); break;
                case 'image':       $types += MimeType::getImageList(); break;
                case 'text':        $types += MimeType::getTextList(); break;
                case 'video':       $types += MimeType::getVideoList(); break;
                default:            $types += MimeType::getSubTypeList($mimeType); break;
            }
        }

        return in_array($this->getFile()->type(), $types);
    }
966254
public static function isImage($mimeType)
    {
        if (in_array($mimeType, self::$mimeTypes, true)) {
            return (bool)preg_match('|^image/.+$|', $mimeType);
        }

        return false;
    }
742679
public static function getByMimeType(?string $mimeType): int
    {
        switch (explode('/', (string) $mimeType)[0] ?? null) {
            case 'image':
                return static::IMAGE;
            case 'audio':
                return static::AUDIO;
            case 'video':
                return static::VIDEO;
            default:
                return static::FILE;
        }
    }
513444
private function filterMimeType(string $mimetype): string
    {
        if ('' == $mimetype) {
            return static::DEFAULT_MIMETYPE;
        }

        if (1 === preg_match(static::REGEXP_MIMETYPE, $mimetype)) {
            return $mimetype;
        }

        throw new SyntaxError(sprintf('invalid mimeType, `%s`', $mimetype));
    }
1039951
public static function File($filename, $mimetype = '', $postname = '')
    {
        if (class_exists('CURLFile')) {
            return new \CURLFile($filename, $mimetype, $postname);
        }

        if (function_exists('curl_file_create')) {
            return curl_file_create($filename, $mimetype, $postname);
        }

        return sprintf('@%s;filename=%s;type=%s', $filename, $postname ?: basename($filename), $mimetype);
    }
298012
public function readString($data, $mimeType = null)
    {
        return $this->schemaFactory()->create(
            $this->reader()->readString($data, $mimeType)
        );
    }