You are here

public function FileSystemInterface::move in Drupal 9

Same name and namespace in other branches
  1. 8 core/lib/Drupal/Core/File/FileSystemInterface.php \Drupal\Core\File\FileSystemInterface::move()

Moves a file to a new location without database changes or hook invocation.

This is a powerful function that in many ways performs like an advanced version of rename().

  • Checks if $source and $destination are valid and readable/writable.
  • Checks that $source is not equal to $destination; if they are an error is reported.
  • If file already exists in $destination either the call will error out, replace the file or rename the file based on the $replace parameter.
  • Works around a PHP bug where rename() does not properly support streams if safe_mode or open_basedir are enabled.

Parameters

string $source: A string specifying the filepath or URI of the source file.

string $destination: A URI containing the destination that $source should be moved to. The URI may be a bare filepath (without a scheme) and in that case the default scheme (public://) will be used.

int $replace: Replace behavior when the destination file already exists:

Return value

string The path to the new file.

Throws

\Drupal\Core\File\Exception\FileException Implementation may throw FileException or its subtype on failure.

See also

https://bugs.php.net/bug.php?id=60456

1 method overrides FileSystemInterface::move()
FileSystem::move in core/lib/Drupal/Core/File/FileSystem.php
Moves a file to a new location without database changes or hook invocation.

File

core/lib/Drupal/Core/File/FileSystemInterface.php, line 359

Class

FileSystemInterface
Provides an interface for helpers that operate on files and stream wrappers.

Namespace

Drupal\Core\File

Code

public function move($source, $destination, $replace = self::EXISTS_RENAME);