English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Basic PHP Tutorial

Advanced PHP Tutorial

PHP & MySQL

PHP Reference Manual

PHP chgrp() Function Usage and Example

PHP Filesystem Reference Manual

The chgrp() function can be used to change the user group of the specified file.

Syntax

bool chgrp ( string filename, mixed group )

The above function attempts to change the group of the file filename to group (specified by group name or group ID).
Only superusers can modify the file group arbitrarily, other users may only change the file group to the group where the user is located.
If successful, this function can return TRUE; if failed, it can return FALSE.

Online Example

<?php
   $filename = "/PhpProject/sample.txt";
   $format = "%s's Group ID @ %s: %d\n";
   printf($format, $filename, date('r'), filegroup($filename));
   chgrp($filename, "admin");
   clearstatcache();  //Do not cache the result of filegroup()
   printf($format, $filename, date('r'), filegroup($filename));
?>

Output Result

/PhpProject/sample.txt's Group ID @ Fri, 22 May 2020 07:42:21 +0200: 0
/PhpProject/sample.txt's Group ID @ Fri, 22 May 2020 07:42:21 +0200: 0

PHP Filesystem Reference Manual