277 of 410 menu

The chgrp Function

The chgrp function changes the group for the specified file. The first parameter of the function is the file path, the second is the name or ID of the new group. Appropriate permissions are required for the function to execute successfully.

Syntax

chgrp(string $filename, string|int $group): bool

Example

Let's change the group of the file 'test.txt' to 'www-data':

<?php $res = chgrp('test.txt', 'www-data'); var_dump($res); ?>

Code execution result:

true

Example

Let's try to change the group of a non-existent file:

<?php $res = chgrp('nonexistent.txt', 'www-data'); var_dump($res); ?>

Code execution result:

false

Example

Using a numeric group ID instead of a name:

<?php $res = chgrp('test.txt', 33); // 33 is a typical ID for the www-data group var_dump($res); ?>

Code execution result:

true

See Also

  • the chmod function,
    which changes access permissions
  • the chown function,
    which changes the file owner
byenru