Friday, October 10, 2025
HomeLanguagesPHP chgrp( ) Function

PHP chgrp( ) Function

The chgrp() function in PHP is an inbuilt function that is used to change the user group of the specified file. It returns true on success and false on failure. Only the superuser has the right to change the group of a file arbitrarily.

Syntax: 
 

bool chgrp ( $filename, $group )

Parameters: The chgrp() function in PHP accepts two parameters which are filename and user. 
 

  1. $filename: It specifies the file whose user group you want to change.
  2. $group: It specifies the new user group. It can be a group name or a number.

Return Value: The chgrp() function returns true on success and false on failure.
Errors And Exception
 

  1. The chgrp() function in PHP doesn’t works for remote files.It only works on files which are accessible by the server’s filesystem.
  2. PHP checks whether the files or directories which are being operated have the same owner as the script that is being executed or not when safe mode is enabled.

Examples: 
 

Input : chgrp("gfg.txt", "administrator")
Output :true

Input : $filename = "/user/Desktop/neveropen/gfg.txt";
        chgrp( $filename, "guest" );
Output :true

Below programs illustrate the chgrp() function:
Program 1
 




<?php
  
// changes the file group to administrator
chgrp("gfg.txt", "administrator")
  
?>


Output: 
 

true

Program 2
 




<?php
  
// Changes the file group to guest
$filename = "/user/Desktop/neveropen/gfg.txt";
  
chgrp ( $filename, "guest" );
  
chown($path, $user_name); 
  
?>


Output:

true

Reference: 
http://php.net/manual/en/function.chgrp.php

Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32350 POSTS0 COMMENTS
Milvus
87 POSTS0 COMMENTS
Nango Kala
6718 POSTS0 COMMENTS
Nicole Veronica
11880 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11941 POSTS0 COMMENTS
Shaida Kate Naidoo
6838 POSTS0 COMMENTS
Ted Musemwa
7099 POSTS0 COMMENTS
Thapelo Manthata
6794 POSTS0 COMMENTS
Umr Jansen
6794 POSTS0 COMMENTS