You are here

public function FileinfoMimeTypeGuesser::guess in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/symfony/http-foundation/File/MimeType/FileinfoMimeTypeGuesser.php \Symfony\Component\HttpFoundation\File\MimeType\FileinfoMimeTypeGuesser::guess()

Guesses the mime type of the file with the given path.

Parameters

string $path The path to the file:

Return value

string The mime type or NULL, if none could be guessed

Throws

FileNotFoundException If the file does not exist

AccessDeniedException If the file could not be read

Overrides MimeTypeGuesserInterface::guess

File

vendor/symfony/http-foundation/File/MimeType/FileinfoMimeTypeGuesser.php, line 51

Class

FileinfoMimeTypeGuesser
Guesses the mime type using the PECL extension FileInfo.

Namespace

Symfony\Component\HttpFoundation\File\MimeType

Code

public function guess($path) {
  if (!is_file($path)) {
    throw new FileNotFoundException($path);
  }
  if (!is_readable($path)) {
    throw new AccessDeniedException($path);
  }
  if (!self::isSupported()) {
    return;
  }
  if (!($finfo = new \finfo(FILEINFO_MIME_TYPE, $this->magicFile))) {
    return;
  }
  return $finfo
    ->file($path);
}