PHP filegroup() Function
Last Updated :
29 Mar, 2023
The filegroup() is an inbuilt function in PHP that returns the filegroup. This function returns a group id that can resolve using posix_getgrigid() to a name.
Syntax:
filegroup(string $filename): int|false
Parameter: This function has only one parameter.
- filename: A name of the file or path of the file
Return value: This function returns the numerical group id if the function is successful otherwise the function will return “false”. Group id can resolve using the posix_getgrgid() function.
Example 1: The following code demonstrates the filegroup() function.
PHP
<?php
$file = 'text.txt' ;
$group_id = filegroup ( $file );
$expected_group_id = 1000;
if ( $group_id === $expected_group_id ) {
echo "The file $file is owned by the expected group." ;
} else {
echo "The file $file is not owned by the expected group." ;
}
?>
|
Output:
The file text.txt is owned by the expected group.
Example 2: In this program, we will print the group id of the file.
PHP
<?php
$fileName = 'text.txt' ;
print_r( filegroup ( $fileName ));
?>
|
Note: Output will be different according to your system.
Output:
1000
Reference: https://www.php.net/manual/en/function.filegroup.php
Share your thoughts in the comments
Please Login to comment...