PHP Filesystem filegroup(1) Function
The PHP Filesystem filegroup() function is used to return a group ID of the given file. If it is successful, the function can return an ID of the group to which the specified file belongs. If it fails, then returns false.
This function can not be run on Windows systems, use the posix_getgrgid() function to convert the group ID to the group name.
Syntax
Below is the syntax of the PHP Filesystem filegroup() function −
int filegroup ( string $filename )
Parameters
The parameters are needed to use the filegroup() function are mentioned below −
| Sr.No | Parameter & Description |
|---|---|
| 1 |
filename(Required) The path to the file. |
Return Value
It returns group ID on success, or FALSE on failure.
PHP Version
The filegroup() function was first introduced as part of core PHP 4 and work well with the PHP 5, PHP 7, PHP 8.
Example
In the below example code we have used PHP Filesystem filegroup() function to get the group ID of the specified file. And echo is used to print the group ID to the screen.
<?php //Path of the file you are using $filename = "/PhpProject/sample.txt"; //Echo the group id of the file echo filegroup($filename); ?>
Output
This will create the below outcome −
0
Example
In this example we are going to get a group id of the log file. And it prints the group ID to the screen.
<?php //Path of the log file $filename = "/PhpProject/log/syslog"; echo "Group ID of the log file: " . filegroup($filename); ?>
Output
This will generate the following result −
Group ID of the log file: 4
Example - Check Group ID for a Temporary File
Now we will check the group ID of a temporary file. And it will print the group ID to the screen.
<?php //Path of the temporary test file $filename = "/PhpProject/tmp/testfile.tmp"; echo "Group ID of the temporary file: " . filegroup($filename); ?>
Output
This will produce the following result −
Group ID of the temporary file: 1000
Note
The filegroup() method is particularly useful for tasks related to system administration, security audits, and application access control management.
Summary
In PHP, filegroup() method can be used to find a file's group ID. This ID (a number), represents the group that owns the file. Different files may have different group IDs depending on their ownership settings.