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

Breadcrumb

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

function Filesystem::chown

Change the owner of an array of files or directories.

This method always throws on Windows, as the underlying PHP function is not supported.

Parameters

string|int $user A user name or number:

bool $recursive Whether change the owner recursively or not:

Throws

IOException When the change fails

See also

https://www.php.net/chown

File

vendor/symfony/filesystem/Filesystem.php, line 235

Class

Filesystem
Provides basic utility to manipulate the file system.

Namespace

Symfony\Component\Filesystem

Code

public function chown(string|iterable $files, string|int $user, bool $recursive = false) : void {
    foreach ($this->toIterable($files) as $file) {
        if ($recursive && is_dir($file) && !is_link($file)) {
            $this->chown(new \FilesystemIterator($file), $user, true);
        }
        if (is_link($file) && \function_exists('lchown')) {
            if (!self::box('lchown', $file, $user)) {
                throw new IOException(\sprintf('Failed to chown file "%s": ', $file) . self::$lastError, 0, null, $file);
            }
        }
        else {
            if (!self::box('chown', $file, $user)) {
                throw new IOException(\sprintf('Failed to chown file "%s": ', $file) . self::$lastError, 0, null, $file);
            }
        }
    }
}

API Navigation

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