Syntax:bool DirectoryIterator::isFile (void)
Parameters:this function takes no parameters.
Return value:this function returns TRUE if the file exists and is a regular file (not a link or dir), otherwise FALSE.The following programs illustrate the DirectoryIterator::isFile() function in PHP:
Program 1:
// Create the Iterator directory
$directory
=
new
DirectoryIterator (dirname (
__ FILE__
));
// Loop for each directory item
foreach
(
$directory
as
$dir
) {
// Check the file directory element
if
(
$dir
-> isFile()) {
// Show file name
echo
$dir
-> getFilename().
"
"
;
}
}
?>
Output:applications.html bitnami.css favicon.ico engineer.PNG gfg.php index.php
Program 2:
// Create directory Iterator
$directory
=
new
DirectoryIterator (dirname (
__ FILE__
));
// Loop while the directory is valid
while
(
$directory
-> valid()) {
// Check the file directory element
if
(
$directory
-> isFile()) {
// Show filename
echo
$directory
-> getFilename().
"
"
;
}
// Move to next item
$directory
-> next();
}
?>
Output:applications.html bitnami.css favicon.ico engineer.PNG gfg.php index.php
Note . The output of this function depends on the contents of the server folder.Link: https : //www.php.net/manual/en/directoryiterator.isfile.php