FINFO获取文件MIME

@param string $path
@return string
181170
public static function getFileMimeByFinfo($path)
    {
        if (empty($path) || ! is_file($path)) {
            return null;
        }
        
        $finfo = new \finfo(FILEINFO_MIME_TYPE);
        return $finfo->file($path);
    }
888988
public static function getFileExtention($path)
    {

        $ext = pathinfo($path, PATHINFO_EXTENSION);

        if($ext === ''){
            $splitedPath = explode('.', $path);
            $ext = end($splitedPath);
        }

        return $ext;
    }
1151530
public function getMetadata($path)
    {
        [$prefix, $path] = $this->getPrefixAndPath($path);

        return $this->getFilesystem($prefix)->getMetadata($path);
    }
405397
protected function addFileExtension(string $path): string
    {
        $extension = pathinfo($path, PATHINFO_EXTENSION);
        if (empty($extension)) {
            $path .= $this->extension;
        }

        return $path;
    }
590451
private function removeFileExtensionFromPath($path)
    {
        if (strrpos($path, '.') !== false) {
            $path = substr($path, 0, strrpos($path, '.'));
        }

        return $path;
    }
1302272
public function realpath($path)
    {
        $path = str_replace('\\', '/', rtrim($path, '/'));
        if ($path[0] != '/' && (strlen($path) < 2 || $path[1] != ':')) {
            $path = getcwd() . '/' . $path;
        }
        $parts = explode('/', $path);
        $path = [];
        foreach ($parts as $part) {
            if ($part == '..') {
                array_pop($path);
            } else if ($part != '.') {
                array_push($path, $part);
            }
        }
        return implode('/', $path);
    }
863109
protected function _getContents($path) {
		$contents = '';
		if (($fp = $this->_fopen($path))) {
			while (!feof($fp)) {
			  $contents .= fread($fp, 8192);
			}
			$this->_fclose($fp, $path);
			return $contents;
		}
		return false;
	}
44152
public static function getMimeType($filePath)
    {
        $fInfo = finfo_open(FILEINFO_MIME_TYPE);
        $mime  = finfo_file($fInfo, $filePath);
        finfo_close($fInfo);

        return $mime;
    }
653333
public static function getFileMimeByCmd($path)
    {
        if (empty($path) || ! is_file($path)) {
            return null;
        }
        
        $info = exec('file -ib "' . $path . '"');
        list ($type, $temp) = explode(';', $info);
        return $type;
    }
1075945
protected function formatPath($path)
    {
        $path = trim($path, '/') . '/';
        if (strlen($path) > 1) {
            $path = '/' . $path;
        }

        return $path;
    }
212242
public function getMimeType(string $path): string
    {
        $path = $this->normalizePath($path);
        $this->assertPresent($path);

        return $this->getAdapter()->getMimeType($path);
    }
1231676
public function mimeType($path)
    {
        if ($this->isDirectory($path) || $path == '/') {
            return LocalFilesystem::$directoryMimetype;
        }
        return $this->mimeTypes->typeOfName($path);
    }
376795
private function realPath($path) {
        $tpls    = explode('/', $path);
        $tpls[0] = App::id2dir($tpls[0]);
        $tpl     = implode('/', $tpls);

        return $tpl;
    }
675481
public static function realpath($path)
    {
        // check for stream uri
        if (preg_match('~^[a-z0-9-_.]+://~', $path)) {
            $stats = (file_exists($path))? stat($path) : false;
            if ($stats && isset($stats['realpath'])) {
                return $stats['realpath'];
            }

            return ($stats !== false) ? $path : false;
        }

        return realpath($path);
    }
638005
protected function getFileInformation($path) {
    $file = pathinfo($path);

    $finfo = finfo_open(FILEINFO_MIME_TYPE);
    $mimetype = finfo_file($finfo, $path);
    // Check if mimetype is supported.
    if (!in_array($mimetype, $this->valid_mimes)) {
      if ($mimetype == 'text/plain') {
        $mimetype = 'application/octet-stream';
      }
      else {
        $this->triggerError('Unsupported mime type: ' . $mimetype);
      }
    }

    $contents = file_get_contents($path);

    return [
      'name'      => str_replace(' ', '-', $file['filename']),
      'filename'  => $file['basename'],
      'extension' => $file['extension'],
      'mimetype'  => $mimetype,
      'contents'  => $contents,
      'size'      => strlen($contents)
    ];
  }
819071
protected function getFilePath(string $path): string
    {
        if (empty($path)) {
            $path = $this->fileName;
        }

        return $path;
    }
206615
public static function get($path)
    {
        $ext = strtolower(pathinfo($path, PATHINFO_EXTENSION));
        if (!isset(self::$fileTypes[$ext])) {
            return false;
        }
        return self::$fileTypes[$ext];
    }