PHP Function Reference

PHP filegroup() Function



The PHP filegroup() function returns the group ID of the specified file.

Note: The results of this function are cached. Use clearstatcache() function to clear the cache.

Syntax

filegroup(filename)

Parameters

filename Required. Specify the path to the file to check.

Return Value

Returns the group ID of the specified file, or false if an error occurs. The group ID is returned in numerical format. The posix_getgrgid() function can be used to convert it to a group name.

Exceptions

Upon failure, an E_WARNING is thrown.

Example:

Lets assume that we have a file called test.txt in the current working directory. The example below demonstrates on using this function to get the group ID of this file.

<?php
$filename = 'test.txt';

//getting the group ID
echo "group ID: ".filegroup($filename)."\n";

//getting the groupname
print_r(posix_getgrgid(filegroup($filename)));
?>

The output of the above code will be:

group ID: 33
Array
(
    [name] => www-data
    [passwd] => x
    [members] => Array
        (
        )

    [gid] => 33
)

❮ PHP Filesystem Reference