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

Breadcrumb

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

function FileSystem::copy

Same name in this branch
  1. 11.1.x vendor/composer/composer/src/Composer/Util/Filesystem.php \Composer\Util\Filesystem::copy()
  2. 11.1.x vendor/symfony/filesystem/Filesystem.php \Symfony\Component\Filesystem\Filesystem::copy()

Overrides FileSystemInterface::copy

File

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

Class

FileSystem
Provides helpers to operate on files and stream wrappers.

Namespace

Drupal\Core\File

Code

public function copy($source, $destination, $fileExists = FileExists::Rename) {
    if (!$fileExists instanceof FileExists) {
        // @phpstan-ignore staticMethod.deprecated
        $fileExists = FileExists::fromLegacyInt($fileExists, __METHOD__);
    }
    $this->prepareDestination($source, $destination, $fileExists);
    if (!@copy($source, $destination)) {
        // If the copy failed and realpaths exist, retry the operation using them
        // instead.
        $real_source = $this->realpath($source) ?: $source;
        $real_destination = $this->realpath($destination) ?: $destination;
        if ($real_source === FALSE || $real_destination === FALSE || !@copy($real_source, $real_destination)) {
            throw new FileWriteException("The specified file '{$source}' could not be copied to '{$destination}'.");
        }
    }
    // Set the permissions on the new file.
    $this->chmod($destination);
    return $destination;
}

API Navigation

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