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

Breadcrumb

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

function FileSystem::getDestinationFilename

Overrides FileSystemInterface::getDestinationFilename

1 call to FileSystem::getDestinationFilename()
FileSystem::prepareDestination in core/lib/Drupal/Core/File/FileSystem.php
Prepares the destination for a file copy or move operation.

File

core/lib/Drupal/Core/File/FileSystem.php, line 532

Class

FileSystem
Provides helpers to operate on files and stream wrappers.

Namespace

Drupal\Core\File

Code

public function getDestinationFilename($destination, $fileExists) {
    if (!$fileExists instanceof FileExists) {
        // @phpstan-ignore staticMethod.deprecated
        $fileExists = FileExists::fromLegacyInt($fileExists, __METHOD__);
    }
    $basename = $this->basename($destination);
    if (!Unicode::validateUtf8($basename)) {
        throw new FileException(sprintf("Invalid filename '%s'", $basename));
    }
    if (file_exists($destination)) {
        switch ($fileExists) {
            case FileExists::Replace:
                // Do nothing here, we want to overwrite the existing file.
                break;
            case FileExists::Rename:
                $directory = $this->dirname($destination);
                $destination = $this->createFilename($basename, $directory);
                break;
            case FileExists::Error:
                // Error reporting handled by calling function.
                return FALSE;
        }
    }
    return $destination;
}

API Navigation

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