Introduction
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
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
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
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. |
Example
An example of the function is:
<?php
// Read and write for owner, nothing for everybody else
chmod("test.txt", 0600);
// Read and write for owner, read for everybody else
chmod("test.txt", 0644);
// Everything for owner, read and execute for others
chmod("test.txt", 0755);
// Everything for owner, read and execute for owner's group
chmod("test.txt", 0750);
?>
PHP chown function
The PHP chown function changes the owner of the specified file. Syntax
Parameter of the chown function
The parameters of the function are:
Parameter |
Description |
file |
It specifies the file to check. |
owner |
It specifies the new owner. |
Example
An example of the function is:
<?php
chown("text.txt","atual");
?>