PHP Function Reference

PHP lchgrp() Function



The PHP lchgrp() function attempts to change the group ownership of the specified symbolic link. Only the superuser may change the group ownership of a symlink arbitrarily. Other users may change the group ownership of a symlink to any group of which that user is a member.

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

lchgrp(filename, group)

Parameters

filename Required. Specify the path to the symlink to change the group ownership for.
group Required. Specify the new group by name or number.

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, lchgrp() function is used to change its group ownership.

<?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 group owner of the symbolic link
if(lchgrp($link, 8)){
  echo "Group ownership is successfully changed.\n";
} else {
  echo "Group ownership can not be changed.\n";
}
?>

The output of the above code will be:

Symbolic link has been created.
Group ownership is successfully changed.

❮ PHP Filesystem Reference