PHP | chgrp( ) Function

The chgrp() function in PHP is an inbuilt function which 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 chown() 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/geeksforgeeks/gfg.txt";
        chgrp( $filename, "guest" );
Output :true

Below programs illustrate the chgrp() function:

Program 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Output:

true

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Output:

true

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



My Personal Notes arrow_drop_up

I am a technology enthusiast who has a keen interest in programming I am pursuing Engineering in Computer Science from GEU, Dehradun I like to unwind by watching movies and English sitcomsI have a keen interest in music

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.