PHP | DirectoryIterator getPath()函数
DirectoryIterator::getPath()函数是PHP中的一个内置函数,用于获取当前迭代器项的路径,不包括文件名。
句法:
string DirectoryIterator::getPath( void )
参数:此函数不接受任何参数。
返回值:此函数返回文件路径,省略文件名和任何尾部斜杠。
下面的程序说明了PHP中的 DirectoryIterator::getPath()函数:
方案一:
getPath();
?>
输出:
C:\xampp\htdocs
方案二:
current();
// Display key, filename and its path
echo $dir->key() . " => " .
$file->getFilename() . " | Path: " .
$directory->getPath() . "
";
}
?>
输出:
0 => . | Path: C:\xampp\htdocs
1 => .. | Path: C:\xampp\htdocs
2 => applications.html | Path: C:\xampp\htdocs
3 => bitnami.css | Path: C:\xampp\htdocs
4 => dashboard | Path: C:\xampp\htdocs
5 => favicon.ico | Path: C:\xampp\htdocs
6 => geeks.PNG | Path: C:\xampp\htdocs
7 => gfg.php | Path: C:\xampp\htdocs
8 => img | Path: C:\xampp\htdocs
9 => index.php | Path: C:\xampp\htdocs
10 => webalizer | Path: C:\xampp\htdocs
11 => xampp | Path: C:\xampp\htdocs
注意:此函数的输出取决于服务器文件夹的内容。
参考: https://www. PHP.net/manual/en/directoryiterator.getpath。 PHP