PHP | DirectoryIterator getPerms() Function

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= newDirectoryIterator(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 zambiatek.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= newDirectoryIterator(dirname(__FILE__));// Loop runs for each element of directoryforeach($directoryas$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 zambiatek.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
Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, zambiatek Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
 
				 
					


