PHP | DirectoryIterator isReadable() Function
Last Updated :
07 Mar, 2024
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
$directory = new DirectoryIterator(dirname( __FILE__ ));
foreach ( $directory as $dir ) {
if ( $dir ->isReadable()) {
echo $dir ->getFilename() . "<br>" ;
}
}
?>
|
Output:
.
..
applications.html
bitnami.css
dashboard
favicon.ico
geeks.PNG
gfg.php
img
index.php
Sublime Text Build 3211 x64 Setup.exe
webalizer
xampp
Program 2:
<?php
$directory = new DirectoryIterator(dirname( __FILE__ ));
while ( $directory ->valid()) {
if ( $directory ->isReadable()) {
echo $directory ->getFilename() . "<br>" ;
}
$directory ->next();
}
?>
|
Output:
.
..
applications.html
bitnami.css
dashboard
favicon.ico
geeks.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.
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...