DirectoryIterator::isLink

(PHP 5, PHP 7, PHP 8)

DirectoryIterator::isLinkDetermine if current DirectoryIterator item is a symbolic link

說明

public DirectoryIterator::isLink(): bool

Determines if the current DirectoryIterator item is a symbolic link.

參數(shù)

此函數(shù)沒有參數(shù)。

返回值

Returns true if the item is a symbolic link, otherwise false

范例

示例 #1 A DirectoryIterator::isLink() example

This example contains a recursive function for removing a directory tree.

<?php
/**
 * This function will recursively delete all files in the given path, without
 * following symlinks.
 * 
 * @param string $path Path to the directory to remove.
 */
function removeDir($path) {
    
$dir = new DirectoryIterator($path);
    foreach (
$dir as $fileinfo) {
        if (
$fileinfo->isFile() || $fileinfo->isLink()) {
            
unlink($fileinfo->getPathName());
        } elseif (!
$fileinfo->isDot() && $fileinfo->isDir()) {
            
removeDir($fileinfo->getPathName());
        }
    }
    
rmdir($path);
}

removeDir('foo');
?>

參見