function FileSystemInterface::move

Same name in other branches
  1. 9 core/lib/Drupal/Core/File/FileSystemInterface.php \Drupal\Core\File\FileSystemInterface::move()
  2. 10 core/lib/Drupal/Core/File/FileSystemInterface.php \Drupal\Core\File\FileSystemInterface::move()
  3. 11.x 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 385

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);

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.