PHP | DirectoryIterator isReadable() Function

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= newDirectoryIterator(dirname(__FILE__));  Â// Loop runs for each element of directory foreach($directoryas$dir) {      Â    // Check for readable element     if($dir->isReadable()) {  Â        // Display the filename         echo$dir->getFilename() . "<br>";     } }  Â?>  | 
Output:
. .. applications.html bitnami.css dashboard favicon.ico zambiatek.PNG gfg.php img index.php Sublime Text Build 3211 x64 Setup.exe webalizer xampp
Program 2:
| <?php  Â// Create a directory Iterator $directory= newDirectoryIterator(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 zambiatek.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
 
				 
					


