Get a file extension from a content type

@param string $type The mime or content type to search for
@param string $default A fallback to extension return
@return string
979886
public static function getExtension(
        string $type,
        string $default = "unknown"
    ): string
    {
        return array_key_exists($type, self::$types)
            ? self::$types[$type]
            : $default;
    }
849797
public function getExtensionByType($type)
    {
        if ($this->isValidType($type)) {
            return $this->mime[$type];
        } else {
            throw new RuntimeException(sprintf('Invalid type "%s" supplied', $type));
        }
    }
747554
public function getUploadUrl( $default = null ) {

		$prop = $this->properties[ self::PROP_UPLOAD_URL ];

		if( isset( $prop ) && strlen( $prop ) > 0 ) {

			return $prop;
		}

		return $default;
	}
1193613
public function getDescription($default = false)
    {
        if (($ob = $this->_headers['content-description']) &&
            strlen($ob->value)) {
            return $ob->value;
        }

        return $default
            ? $this->getName()
            : '';
    }
1055207
public function getName($default = false)
    {
        if (!($name = $this->getDispositionParameter('filename')) &&
            !($name = $this->getContentTypeParameter('name')) &&
            $default) {
            $name = preg_replace('|\W|', '_', $this->getDescription(false));
        }

        return $name;
    }
1074636
public function getTypeByExtension($extension)
    {
        if ($this->isValidExtension($extension)) {

            // We get back flipped copy
            $list = $this->getList(true);
            return $list[$extension];

        } else {

            // For all unknown extensions, the default Mime-Type is used
            return 'application/octet-stream';
        }
    }
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);
    }
823734
public function getFiles($type)
	{
		$f = $type . 'Files';

		if (property_exists($this, $f))
		{
			return self::${$f};
		}

		$this->say('Missing Files: ' . $type);

		return "";
	}
412893
public function get_extension($path){
        $type = $this->get_mime($path);
        $match = [];
        $ext = '';
        if( $type ){
            foreach( wp_get_mime_types() as $extensions => $content_type ){
                if( $content_type == $type ){
                    $ext = explode('|', $extensions)[0];
                    break;
                }
            }
        }
        return $ext;
    }
1360409
public static function getFileMime($filename, $default = 'application/octet-stream')
    {
        if(function_exists('mime_content_type'))
        {
            return mime_content_type($filename);
        }

        $mime_types = array(

            'txt' => 'text/plain',
            'htm' => 'text/html',
            'html' => 'text/html',
            'php' => 'text/html',
            'css' => 'text/css',
            'js' => 'application/javascript',
            'json' => 'application/json',
            'xml' => 'application/xml',
            'swf' => 'application/x-shockwave-flash',
            'flv' => 'video/x-flv',

            // images
            'png' => 'image/png',
            'jpe' => 'image/jpeg',
            'jpeg' => 'image/jpeg',
            'jpg' => 'image/jpeg',
            'gif' => 'image/gif',
            'bmp' => 'image/bmp',
            'ico' => 'image/vnd.microsoft.icon',
            'tiff' => 'image/tiff',
            'tif' => 'image/tiff',
            'svg' => 'image/svg+xml',
            'svgz' => 'image/svg+xml',

            // archives
            'zip' => 'application/zip',
            'rar' => 'application/x-rar-compressed',
            'exe' => 'application/x-msdownload',
            'msi' => 'application/x-msdownload',
            'cab' => 'application/vnd.ms-cab-compressed',

            // audio/video
            'mp3' => 'audio/mpeg',
            'qt' => 'video/quicktime',
            'mov' => 'video/quicktime',

            // adobe
            'pdf' => 'application/pdf',
            'psd' => 'image/vnd.adobe.photoshop',
            'ai' => 'application/postscript',
            'eps' => 'application/postscript',
            'ps' => 'application/postscript',

            // ms office
            'doc' => 'application/msword',
            'rtf' => 'application/rtf',
            'xls' => 'application/vnd.ms-excel',
            'ppt' => 'application/vnd.ms-powerpoint',

            // open office
            'odt' => 'application/vnd.oasis.opendocument.text',
            'ods' => 'application/vnd.oasis.opendocument.spreadsheet',
        );

        $ext = substr(strrchr($filename, "."), 1);

        if (array_key_exists($ext, $mime_types))
        {
            return $mime_types[$ext];
        }
        elseif (function_exists('finfo_open'))
        {
            $finfo = finfo_open(FILEINFO_MIME);
            $mimetype = finfo_file($finfo, $filename);
            finfo_close($finfo);
            return $mimetype;
        }        

        return $default;
    }
263741
public function getFile($key = null, $default = null)
    {
        if (null === $key) {
            $files = [];
            foreach ($_FILES as $key => $FILE){
                $files[$key] = $this->formatFileInfo($FILE);
            }
            return $files;
        } else {
            $file = array_get($_FILES, $key, $default);
            $file = $this->formatFileInfo($file);
            return $file;
        }
    }
379
public function getExtension($mimetype)
    {
        if (!($extension = array_search($mimetype, $this->mainMimeTypes))) {
            $extension = array_search($mimetype, $this->mimeTypes);
        }

        return !$extension ? null : $extension;
    }
816067
public static function getExtFromType($type, $primary = false) {
        $exts = array();

        foreach (self::$_types as $ext => $mimeType) {
            $isPrimary = false;

            if (is_array($mimeType)) {
                $mimeType = $mimeType[0];
                $isPrimary = $mimeType[1];
            }

            if ($mimeType == $type) {
                if ($primary && $isPrimary) {
                    return $ext;
                }

                $exts[] = $ext;
            }
        }

        if ($primary && isset($exts[0])) {
            return $exts[0];
        }

        return $exts;
    }
605209
private function getFileBackType($type)
    {
        switch ($type) {
            case Mirakl::DOCUMENT_LEGAL_IDENTITY_OF_REPRESENTATIVE:
                return Mirakl::DOCUMENT_LEGAL_IDENTITY_OF_REP_REAR;
            case Mirakl::DOCUMENT_SOLE_MAN_BUS_IDENTITY:
                return Mirakl::DOCUMENT_SOLE_MAN_BUS_IDENTITY_REAR;
            default:
                return false;
        }
    }
875648
public function getContent($type = 'default') {

		if(false === is_string($type)) {
			return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($type)), E_USER_ERROR);
		}

		if(false === is_dir($this -> directory -> getPath())) {
			return trigger_error(sprintf('Directory "%s" does not exists', $this -> directory -> getPath()), E_USER_ERROR);	
		}

		$files = array_values(array_diff(scandir($this -> directory -> getPath()), ['.', '..']));

		switch($type) {

			case 'array' : 
				return $files;

			case 'object' :
				return (object) $files;

			case 'json' :
				return json_encode($files);

			default : 

				$content = [];

				foreach($files as $file) {

					if(is_dir($this -> directory -> getPath() . $file)) {
						
						$content[] = new Directory($file);
						continue;
					}

					$content[] = new File($file);
				}

				return $content;
		}
	}
502066
public function getTypeConfig($type = self::NORMAL, $default = [])
    {
        if ($this->isTypeAvailable($type)) {
            return $this->pageTypesAvailable[$type];
        }

        return $default;
    }
129641
public static function getExtByMimeType(string $type): string
    {
        $value = array_search(strtolower($type), self::getMimeTypes(), true);

        return $value ?: '';
    }