Skip to content

guessExtension() #1367

Description

@nowackipawel

Am I wrong or this code does not have sense:

	public static function guessExtensionFromType(string $type) // $type contains MIME TYPE like 'image/jpeg'
	{
		$type = trim(strtolower($type), '. ');

		foreach (self::$mimes as $ext => $types)
		{
			if (is_string($types) && $types == $type)
			{
				return $ext;
			}
			else if (is_array($types) && in_array($type, $types))
			{
				return $ext;
			}
		}

		return null;
	}

for extensions like, i.e.:


	public static $mimes = [

		'mid'   => 'audio/midi',
		'midi'  => 'audio/midi',
		'mpga'  => 'audio/mpeg',
		'mp2'   => 'audio/mpeg',

		'jpg'   => ['image/jpeg', 'image/pjpeg'],
		'jpeg'  => ['image/jpeg', 'image/pjpeg'],
		'jpe'   => ['image/jpeg', 'image/pjpeg'],
		'jp2'   => ['image/jp2', 'video/mj2', 'image/jpx', 'image/jpm'],
		'j2k'   => ['image/jp2', 'video/mj2', 'image/jpx', 'image/jpm'],
		'jpf'   => ['image/jp2', 'video/mj2', 'image/jpx', 'image/jpm'],
		'jpg2'  => ['image/jp2', 'video/mj2', 'image/jpx', 'image/jpm'],
		'jpx'   => ['image/jp2', 'video/mj2', 'image/jpx', 'image/jpm'],
		'jpm'   => ['image/jp2', 'video/mj2', 'image/jpx', 'image/jpm'],
		'mj2'   => ['image/jp2', 'video/mj2', 'image/jpx', 'image/jpm'],
		'mjp2'  => ['image/jp2', 'video/mj2', 'image/jpx', 'image/jpm'],
];

for image/jpeg it always returns 'jpg' even if real file extension is jpeg or jpe which are also correct;

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions