PHP | DirectoryIterator isFile() Function
Last Updated :
07 Mar, 2024
The DirectoryIterator::isFile() function is an inbuilt function in PHP which is used to check the current DirectoryIterator item is a regular file or not.
Syntax:
bool DirectoryIterator::isFile( void )
Parameters: This function does not accept any parameters.
Return Value: This function returns TRUE if the file exists and is a regular file (not a link or dir), otherwise FALSE.
Below programs illustrate the DirectoryIterator::isFile() function in PHP:
Program 1:
<?php
$directory = new DirectoryIterator(dirname( __FILE__ ));
foreach ( $directory as $dir ) {
if ( $dir ->isFile()) {
echo $dir ->getFilename() . "<br>" ;
}
}
?>
|
Output:
applications.html
bitnami.css
favicon.ico
geeks.PNG
gfg.php
index.php
Program 2:
<?php
$directory = new DirectoryIterator(dirname( __FILE__ ));
while ( $directory ->valid()) {
if ( $directory ->isFile()) {
echo $directory ->getFilename() . "<br>" ;
}
$directory ->next();
}
?>
|
Output:
applications.html
bitnami.css
favicon.ico
geeks.PNG
gfg.php
index.php
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...