PHP | DirectoryIterator getPerms() Function
Last Updated :
07 Mar, 2024
The DirectoryIterator::getPerms() function is an inbuilt function in PHP that is used to get the permissions of the current DirectoryIterator item.
Syntax:
int DirectoryIterator::getPerms( void )
Parameters: This function does not accept any parameters.
Return Value: This function returns the file permissions as a decimal integer. The below programs illustrate the DirectoryIterator::getPerms() function in PHP.
Program 1:
php
<?php
$directory = new DirectoryIterator(dirname( __FILE__ ));
while ( $directory ->valid()) {
if (! $directory ->isDot()) {
$perms = substr (sprintf( '%o' , $directory ->getPerms()), -4);
echo $directory ->getFilename() . " "
. " | Permission: " . $perms . "<br>" ;
}
$directory ->next();
}
?>
|
Output:
applications.html | Permission: 0666
bitnami.css | Permission: 0666
dashboard | Permission: 0777
favicon.ico | Permission: 0666
geeks.PNG | Permission: 0666
gfg.php | Permission: 0666
img | Permission: 0777
index.php | Permission: 0666
webalizer | Permission: 0777
xampp | Permission: 0777
Program 2:
php
<?php
$directory = new DirectoryIterator(dirname( __FILE__ ));
foreach ( $directory as $dir ) {
if (! $dir ->isDot()) {
$perms = substr (sprintf( '%o' , $dir ->getPerms()), -4);
echo $dir ->getFilename() . " "
. " | Permission: " . $perms . "<br>" ;
}
}
?>
|
Output:
applications.html | Permission: 0666
bitnami.css | Permission: 0666
dashboard | Permission: 0777
favicon.ico | Permission: 0666
geeks.PNG | Permission: 0666
gfg.php | Permission: 0666
img | Permission: 0777
index.php | Permission: 0666
webalizer | Permission: 0777
xampp | Permission: 0777
Note: The output of this function depends on the content of the server folder.
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...