Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. File.php

function File::guessExtension

Returns the extension based on the mime type.

If the mime type is unknown, returns null.

This method uses the mime type as guessed by getMimeType() to guess the file extension.

See also

MimeTypes

getMimeType()

File

vendor/symfony/http-foundation/File/File.php, line 53

Class

File
A file in the file system.

Namespace

Symfony\Component\HttpFoundation\File

Code

public function guessExtension() : ?string {
    if (!class_exists(MimeTypes::class)) {
        throw new \LogicException('You cannot guess the extension as the Mime component is not installed. Try running "composer require symfony/mime".');
    }
    return MimeTypes::getDefault()->getExtensions($this->getMimeType())[0] ?? null;
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal