Thursday, June 18, 2026
HomeLanguagesPHP | DirectoryIterator isReadable() Function

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 = 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

RELATED ARTICLES

Most Popular

Dominic
32516 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6898 POSTS0 COMMENTS
Nicole Veronica
12014 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12109 POSTS0 COMMENTS
Shaida Kate Naidoo
7019 POSTS0 COMMENTS
Ted Musemwa
7262 POSTS0 COMMENTS
Thapelo Manthata
6976 POSTS0 COMMENTS
Umr Jansen
6965 POSTS0 COMMENTS