MimeTypeGuesser::guess

public MimeTypeGuesser::guess($path)

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

core/lib/Drupal/Core/File/MimeType/MimeTypeGuesser.php, line 54

Class

MimeTypeGuesser
Defines a MIME type guesser that also supports stream wrapper paths.

Namespace

Drupal\Core\File\MimeType

Code

public function guess($path) {
  if ($wrapper = $this->streamWrapperManager->getViaUri($path)) {
    // Get the real path from the stream wrapper, if available. Files stored
    // in remote file systems will not have one.
    $real_path = $wrapper->realpath();
    if ($real_path !== FALSE) {
      $path = $real_path;
    }
  }

  if ($this->sortedGuessers === NULL) {
    // Sort is not triggered yet.
    $this->sortedGuessers = $this->sortGuessers();
  }

  foreach ($this->sortedGuessers as $guesser) {
    $mime_type = $guesser->guess($path);
    if ($mime_type !== NULL) {
      return $mime_type;
    }
  }
}
doc_Drupal
2016-10-29 09:28:26
Comments
Leave a Comment

Please login to continue.