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// Create a directory Iterator$directory = new DirectoryIterator(dirname(__FILE__));// Loop runs while directory is validwhile ($directory->valid()) { // If not a dot folder if (!$directory->isDot()) { $perms = substr(sprintf('%o', $directory->getPerms()), -4); // Display the filename with permission echo $directory->getFilename() . " " . " | Permission: " . $perms . "<br>"; } $directory->next();}?> |
Output:
applications.html | Permission: 0666 bitnami.css | Permission: 0666 dashboard | Permission: 0777 favicon.ico | Permission: 0666 neveropen.PNG | Permission: 0666 gfg.php | Permission: 0666 img | Permission: 0777 index.php | Permission: 0666 webalizer | Permission: 0777 xampp | Permission: 0777
Program 2:
php
<?php// Create a directory Iterator$directory = new DirectoryIterator(dirname(__FILE__));// Loop runs for each element of directoryforeach($directory as $dir) { // If not a dot folder if (!$dir->isDot()) { $perms = substr(sprintf('%o', $dir->getPerms()), -4); // Display the filename with permission echo $dir->getFilename() . " " . " | Permission: " . $perms . "<br>"; }}?> |
Output:
applications.html | Permission: 0666 bitnami.css | Permission: 0666 dashboard | Permission: 0777 favicon.ico | Permission: 0666 neveropen.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.
Reference: https://www.php.net/manual/en/directoryiterator.getperms.php
