PHP DirectoryIterator getFilename () Function

PHP

Syntax:
string DirectoryIterator::getFilename (void)
Parameters:This function takes no parameters.Return value:This function returns the file name of the current DirectoryIterator item.The following programs illustrate function DirectoryIterator::getFilename() in PHP:Program 1:  
// Create an Iterator directory $directory = new DirectoryIterator (dirname ( __ FILE__ ));  
// Loop is performed for each item in the directory foreach ( $directory as $dir ) { // Show file name echo $dir -> getFilename(). "< br >" ; }
?>
Output:
. .. applications.html bitnami.css dashboard favicon.ico engineer.PNG gfg.php img index.php webalizer xampp
Program 2:  
/ / Create Iterator Directory $directory = new DirectoryIterator (dirname ( __ FILE__ ));  
// Loop while the directory is valid while ( $directory -> valid()) { // Check that the file is not a directory if (! $directory -> isDir ( )) { // Show file name echo $directory -> getFilename(). "< br >" ; } // 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.getfilename.php



Get Solution for free from DataCamp guru