The PHP file system functions allow you to access and manipulate the filesyaytem. The filesystem functions are part of the PHP core. There is no installation necessary to use these functions. So in this article I describe the PHP filesystem functions basename, chgrp, chmode and chown.
PHP basename function
The PHP basename function returns the trailing component of a path.
Syntax
| basename (path, suffix) |
Parameters of the basename function
The parameters of the function are:
| Parameter | Description |
| path | It specifies the path to check. |
| suffix | It specifies the file extention. |
Example
An example of the function is:
<?php
$path = "test.php";
//Show filename with file extension
echo basename($path) ."<br/>";
echo basename($path,".php");
?>
Output

PHP chgrp function
The PHP chgrp function changes the file group and it returns true on success or false on failure.
Syntax
| chgrp (file, group) |
Parameter of the chgrp function
The parameters of the function are:
| Parameter | Description |
| file | It specifies the file to check. |
| group | It specifies a group name or number. |
Example
An example of the function is:
<?php|
chgrp("test.txt","admin")
?>
PHP chmode function
The PHP chmode function changes the permission of the specified file and it returns true on success or false on failure.
Syntax
| chmode (file, mode) |
Parameter of the chmode function
The parameters of the function are:
| Parameter | Description |
| file | It specifies the file to check. |
| mode | It specifies the new permission. |

Join the conversation! Your thoughts help the community grow.