PHP | DirectoryIterator getType() Function Last Updated : 07 Mar, 2024 Comments Improve Suggest changes Like Article Like Report The DirectoryIterator::getType() function is an inbuilt function in PHP which is used to check the type of the current DirectoryIterator item. Syntax: string DirectoryIterator::getType( void ) Parameters: This function does not accept any parameters. Return Value: This function returns a string which represents the type of the file. The type may be one of the file, link, or dir. Below programs illustrate the DirectoryIterator::getType() function in PHP: Program 1: php <?php // Create a directory Iterator $directory = new DirectoryIterator(dirname(__FILE__)); // Loop runs while directory is valid while ($directory->valid()) { // Check it is directory or not if ($directory->isDir()) { $file = $directory->current(); echo $file->getFilename() . " | Type: " . $directory->getType() . "<br>"; } // Move to the next element of DirectoryIterator $directory->next(); } ?> Output: . | Type: dir .. | Type: dir dashboard | Type: dir img | Type: dir webalizer | Type: dir xampp | Type: dir Program 2: php <?php // Create a directory Iterator $directory = new DirectoryIterator(dirname(__FILE__)); // Loop runs for each element of directory foreach($directory as $dir) { $file = $directory->current(); echo $dir->key() . " => " . $file->getFilename() . " | Type: " . $dir->getType() . "<br>"; } ?> Output: 0 => . | Type: dir 1 => .. | Type: dir 2 => applications.html | Type: file 3 => bitnami.css | Type: file 4 => dashboard | Type: dir 5 => favicon.ico | Type: file 6 => geeks.PNG | Type: file 7 => gfg.php | Type: file 8 => img | Type: dir 9 => index.php | Type: file 10 => webalizer | Type: dir 11 => xampp | Type: dir Note: The output of this function depends on the content of server folder. Comment More infoAdvertise with us Next Article PHP | DirectoryIterator getType() Function jit_t Follow Improve Article Tags : Web Technologies PHP PHP-function PHP-Iterators Similar Reads PHP | DirectoryIterator getATime() Function The DirectoryIterator::getATime() function is an inbuilt function in PHP which is used to get the last access time of the current DirectoryIterator item. Syntax: int DirectoryIterator::getATime( void ) Parameters: This function does not accept any parameters. Return Value: This function returns the 2 min read PHP | DirectoryIterator getPerms() Function The DirectoryIterator::getPerms() function is an inbuilt function in PHP that is used to get the permissions of the current DirectoryIterator item. Syntax: int DirectoryIterator::getPerms( void ) Parameters: This function does not accept any parameters. Return Value: This function returns the file 2 min read PHP | DirectoryIterator getCTime() Function The DirectoryIterator::getCTime() function is an inbuilt function in PHP which is used to get the inode change time of the current DirectoryIterator item. Syntax: int DirectoryIterator::getCTime( void ) Parameters: This function does not accept any parameters. Return Value: This function returns the 2 min read PHP | DirectoryIterator getMTime() Function The DirectoryIterator::getMTime() function is an inbuilt function in PHP which is used to returns the last modification time of the current DirectoryIterator item. Syntax: int DirectoryIterator::getMTime( void ) Parameters: This function does not accept any parameters. Return Value: This function re 2 min read PHP | DirectoryIterator getPath() Function The DirectoryIterator::getPath() function is an inbuilt function in PHP which is used to get the path of current Iterator item without filename. Syntax: string DirectoryIterator::getPath( void ) Parameters: This function does not accept any parameters. Return Value: This function returns the file pa 2 min read Like