DirectoryIterator::getPath()函數是PHP中的內置函數,用於獲取不帶文件名的當前Iterator項的路徑。
用法:
string DirectoryIterator::getPath( void )
參數:該函數不接受任何參數。
返回值:此函數返回文件路徑,省略文件名和任何斜杠。
以下示例程序旨在說明PHP中的DirectoryIterator::getPath()函數:
示例1:
<?php
// Create a directory Iterator
$directory = new DirectoryIterator(dirname(__FILE__));
// Display the path
echo $directory->getPath();
?>
輸出:
C:\xampp\htdocs
示例2:
<?php
// Create a directory Iterator
$directory = new DirectoryIterator(dirname(__FILE__));
// Loop runs for each element of directory
foreach($directory as $dir) {
$file = $directory->current();
// Display key, filename and its path
echo $dir->key() . " => " .
$file->getFilename() . " | Path: " .
$directory->getPath() . "<br>";
}
?>
輸出:
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
相關用法
- PHP SplFileInfo getPath()用法及代碼示例
- PHP DirectoryIterator next()用法及代碼示例
- PHP DirectoryIterator key()用法及代碼示例
- PHP DirectoryIterator __toString()用法及代碼示例
- PHP DirectoryIterator getType()用法及代碼示例
- PHP DirectoryIterator valid()用法及代碼示例
- PHP DirectoryIterator isExecutable()用法及代碼示例
- PHP DirectoryIterator getATime()用法及代碼示例
- PHP DirectoryIterator isDot()用法及代碼示例
- PHP DirectoryIterator current()用法及代碼示例
- PHP DirectoryIterator __construct()用法及代碼示例
- PHP DirectoryIterator getSize()用法及代碼示例
- PHP DirectoryIterator rewind()用法及代碼示例
- PHP DirectoryIterator isDir()用法及代碼示例
- PHP DirectoryIterator isWritable()用法及代碼示例
注:本文由純淨天空篩選整理自jit_t大神的英文原創作品 PHP | DirectoryIterator getPath() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。