PHP | FilesystemIterator __construct() Function
Last Updated :
26 Nov, 2019
The FilesystemIterator::__construct() function is an inbuilt function in PHP which is used to construct a new filesystem iterator.
Syntax:
public FilesystemIterator::__construct( string $path, int $flags )
Parameters: This function accepts two parameters as mentioned above and described below:
- $path: This parameter holds the path of the filesystem item.
- $flags: This parameter holds the flag which provides the affect and behavior of some methods.
Return Value: This function does not return any value.
Below programs illustrate the FilesystemIterator::__construct() function in PHP:
Program 1:
<?php
$fileItr = new FilesystemIterator(dirname( __FILE__ ));
foreach ( $fileItr as $file ) {
echo $file ->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
$fileItr = new FilesystemIterator(dirname( __FILE__ ));
while ( $fileItr ->valid()) {
if ( $fileItr ->isDir()) {
echo $fileItr ->getFilename() . "<br>" ;
}
$fileItr ->next();
}
?>
|
Output:
dashboard
img
webalizer
xampp
Note: The output of this function depends on the content of server folder.
Reference: https://www.php.net/manual/en/filesystemiterator.construct.php
Share your thoughts in the comments
Please Login to comment...