Get a file extension type based on the file MIME info.


@param string $path The file.

@return null|string The extension.
328391
public function getMimeTypeByExtension($path){

        if(!$this->mimeCache){
            $this->mimeCache = require \App::getAlias('disco.mime');
        }//if

        if(isset($this->mimeCache[$this->getExtension($path)])){
            return $this->mimeCache[$this->getExtension($path)];
        }//if

        return null;

    }
740791
protected function getExtension($path)
    {
        $extensions = array_keys($this->extensions);

        return array_first($extensions, function($key, $value) use ($path)
        {
            return ends_with($path, $value);
        });
    }
14754
protected function fromFileType($path)
    {
        switch( Filesystem::getExtension($path) )
        {
            case 'png' : return imagecreatefrompng($path);
            case 'gif' : return imagecreatefromgif($path);
            case 'jpg' :
            case 'jpeg':
            default    : return imagecreatefromjpeg($path);
        }
    }
1140194
public static function _getMIME ($path)
	{
		
		// Check file exists
		
		if (!parent::_Exists ($path))
		{
			return FALSE;
		}
		
		// Get image data
		
		$arrData	= getimagesize ($path);
		
		// Return mime type
		
		return $arrData[2];
		
	}
339132
public static function type(string $path): string
    {
        $result = @filetype($path);
        return $result !== false ? $result : '';
    }
819925
public function getByPath($path)
    {
        $extension = pathinfo($path, PATHINFO_EXTENSION);
        if ('' === $extension) {
            $extension = null;
        }

        return $this->get($extension);
    }
1096007
private function getFileExtensionFromFilepath($filepath)
    {
        $fileExtension = pathinfo($filepath, PATHINFO_EXTENSION);

        if (empty($fileExtension)) {
            throw new \Exception('File extension not found');
        }

        return $fileExtension;
    }
44152
public static function getMimeType($filePath)
    {
        $fInfo = finfo_open(FILEINFO_MIME_TYPE);
        $mime  = finfo_file($fInfo, $filePath);
        finfo_close($fInfo);

        return $mime;
    }
141932
public function setFileInfoFromPath($path)
    {
        $info = pathinfo($path);
        $this->dirname = array_key_exists('dirname', $info) ? $info['dirname'] : null;
        $this->basename = array_key_exists('basename', $info) ? $info['basename'] : null;
        $this->extension = array_key_exists('extension', $info) ? $info['extension'] : null;
        $this->filename = array_key_exists('filename', $info) ? $info['filename'] : null;

        if (file_exists($path) && is_file($path)) {
            $this->mime = finfo_file(finfo_open(FILEINFO_MIME_TYPE), $path);
        }

        return $this;
    }
1288295
public function getMimetype($path)
    {
        $metadata = $this->read($path);

        if ($metadata === false) {
            return false;
        }

        $metadata['mimetype'] = Util::guessMimeType($path, $metadata['contents']);

        return $metadata;
    }
211312
public function getContent($path)
    {
        // only a page index was given ?
        if (('0' == $path) || (int) ($path) > 0) {
            $path = $this->findByIndex($path);
        } else {
            $path = $this->basePath . '/' . $path;
            $infos = pathinfo($path);
            // was the extension given ?
            if (empty($infos['extension'])) {
                $path .= '.md';
            }
        }
        if (file_exists($path)) {
            return file_get_contents($path);
        }

        return false;
    }
371404
function mimeType( path ) {
	var extension = path.replace( /.*[./\\]/ , '' ).toLowerCase() ;

	if ( ! mimeType.extension[ extension ] ) {
		// default MIME type, when nothing is found
		return 'application/octet-stream' ;
	}

	return mimeType.extension[ extension ] ;
}
205593
private function searchExtensions($path)
    {
        foreach ($this->fileExtensions as $ext) {
            if (file_exists($path . $ext)) {
                return $path . $ext;
            }
        }

        return false;
    }
1314925
private static function getMimeTypeOfFile($path)
    {
        $fileInfo = finfo_open(FILEINFO_MIME_TYPE);
        $mime     = finfo_file($fileInfo, $path);
        finfo_close($fileInfo);

        return $mime;
    }
793223
function filetype($path)
    {
        $type = $this->_get_stat_cache_prop($path, 'type');
        if ($type === false) {
            return false;
        }

        switch ($type) {
            case NET_SFTP_TYPE_BLOCK_DEVICE:
                return 'block';
            case NET_SFTP_TYPE_CHAR_DEVICE:
                return 'char';
            case NET_SFTP_TYPE_DIRECTORY:
                return 'dir';
            case NET_SFTP_TYPE_FIFO:
                return 'fifo';
            case NET_SFTP_TYPE_REGULAR:
                return 'file';
            case NET_SFTP_TYPE_SYMLINK:
                return 'link';
            default:
                return false;
        }
    }
203660
public static function getTypeForExtension($extension) {
		static::ensureDataLoaded();

		$extension = strtolower($extension);
		foreach (static::$mime_types as $mime_type => $extensions) {
			if (is_array($extensions)) {
				if (in_array($extension, $extensions, true)) {
					return $mime_type;
				}
			} else if ($extension === $extensions) {
				return $mime_type;
			}
		}
	}
693316
protected function getType($path)
    {
        if (Str::endsWith($path, Type::CSV)) {
            return Type::CSV;
        } elseif (Str::endsWith($path, Type::ODS)) {
            return Type::ODS;
        } else {
            return Type::XLSX;
        }
    }