PHP Function Reference

PHP chgrp() Function



The PHP chgrp() function attempts to change the group ownership of the specified file. Only the superuser may change the group ownership of a file arbitrarily. Other users may change the group ownership of a file 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. On Windows, this function fails silently when applied on a regular file.

Syntax

chgrp(filename, group)

Parameters

filename Required. Specify the path to the file to change 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. The example below demonstrates on using this function to change its group ownership.

<?php
$file = 'test.txt';

//changing the group ownership of the file
if(chgrp($file, 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:

Group ownership is successfully changed.

❮ PHP Filesystem Reference