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
File
-
vendor/
symfony/ filesystem/ Filesystem.php, line 235
Class
- Filesystem
- Provides basic utility to manipulate the file system.
Namespace
Symfony\Component\FilesystemCode
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);
}
}
}
}