PHP Function Reference

PHP lchown() Function



The PHP lchown() function attempts to change the owner of the specified symbolic link. Only the superuser may change the owner of a file.

Note: This function doesn't work on remote files as the file to be examined must be accessible via the server's filesystem.

Note: This function is not implemented on Windows platforms.

Syntax

lchown(filename, user)

Parameters

filename Required. Specify the path to the symlink to change owner for.
user Required. Specify the new owner. Can be a user name or a user ID.

Return Value

Returns true on success or false on failure.

Example:

Lets assume that we have a file called test.txt in the current working directory. In the example below a symbolic link is created. Then, lchown() function is used to change its owner.

<?php
$target = 'test.txt';
$link = 'sampleTest';

if(symlink($target, $link)) {
  echo "Symbolic link has been created.\n";
} else {
  echo "Symbolic link can not be created.\n";
}

//changing the owner of the symbolic link
if(lchown($link, 8)){
  echo "Ownership is successfully changed.\n";
} else {
  echo "Ownership can not be changed.\n";
}
?>

The output of the above code will be:

Symbolic link has been created.
Ownership is successfully changed.

❮ PHP Filesystem Reference