PHP chgrp Function: Change File Group Ownership

The article explains PHP’s chgrp function, which changes a file’s group ownership, outlines its syntax, required parameters, permission restrictions, return values, and provides a complete PHP example demonstrating how to modify a file’s group and display the result.

Laravel Tech Community
Laravel Tech Community
Laravel Tech Community
PHP chgrp Function: Change File Group Ownership

chgrp changes the group ownership of a file. It attempts to set the group of $filename to $group (specified by name or numeric ID). Only the superuser can change any file’s group; other users may only set the group to one they belong to.

Signature: bool chgrp(string $filename, mixed $group) Parameters:

filename : Path to the file.

group : Group name or numeric ID.

Return value: Returns TRUE on success, or FALSE on failure.

Example:

<?php
$filename = 'shared_file.txt';
$format = "%s's Group ID @ %s: %d
";
printf($format, $filename, date('r'), filegroup($filename));
chgrp($filename, 8);
clearstatcache();
// do not cache filegroup() results
printf($format, $filename, date('r'), filegroup($filename));
?>
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

BackendPHPSystem CallUnixchgrpFile Permissions
Laravel Tech Community
Written by

Laravel Tech Community

Specializing in Laravel development, we continuously publish fresh content and grow alongside the elegant, stable Laravel framework.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.