Thursday, October 9, 2025
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
32342 POSTS0 COMMENTS
Milvus
87 POSTS0 COMMENTS
Nango Kala
6712 POSTS0 COMMENTS
Nicole Veronica
11876 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11937 POSTS0 COMMENTS
Shaida Kate Naidoo
6833 POSTS0 COMMENTS
Ted Musemwa
7092 POSTS0 COMMENTS
Thapelo Manthata
6786 POSTS0 COMMENTS
Umr Jansen
6789 POSTS0 COMMENTS