The DirectoryIterator::isReadable() function is an inbuilt function in PHP which is used to check the current DirectoryIterator item is readable or not.
Syntax:
bool DirectoryIterator::isReadable( void )
Parameters: This function does not accept any parameters.
Return Value: This function returns TRUE if the file is readable, otherwise returns FALSE.
Below programs illustrate the DirectoryIterator::isReadable() function in PHP:
Program 1:
<?php   // Create a directory Iterator $directory = new DirectoryIterator(dirname( __FILE__ ));   // Loop runs for each element of directory foreach ( $directory as $dir ) {           // Check for readable element     if ( $dir ->isReadable()) {           // Display the filename         echo $dir ->getFilename() . "<br>" ;     } }   ?> |
Output:
. .. applications.html bitnami.css dashboard favicon.ico neveropen.PNG gfg.php img index.php Sublime Text Build 3211 x64 Setup.exe webalizer xampp
Program 2:
<?php   // Create a directory Iterator $directory = new DirectoryIterator(dirname( __FILE__ ));   // Loop runs while element is valid while ( $directory ->valid()) {           // Check for readable element     if ( $directory ->isReadable()) {           // Display the filename         echo $directory ->getFilename() . "<br>" ;     }       // Move to the next element     $directory ->next(); }   ?> |
Output:
. .. applications.html bitnami.css dashboard favicon.ico neveropen.PNG gfg.php img index.php Sublime Text Build 3211 x64 Setup.exe webalizer xampp
Note: The output of this function depends on the content of server folder.
Reference: https://www.php.net/manual/en/directoryiterator.isreadable.php