Using this as a basis:
$iter = new RecursiveDirectoryIterator('../'); foreach (new RecursiveIteratorIterator($iter) as $fileName => $fileInfo) { $fullPath = (string) $fileInfo; }
Each $fileInfo will return a SplFileInfo object. The path and file name are easily accessible in addition to many other methods.
phpSplFileInfo Object ( [pathName:SplFileInfo:private] => ./t.php [fileName:SplFileInfo:private] => t.php )
I may be mistaken, but to access the name of the parent folder, if you do not write it through the tree, the simplest one will use dirname and add ../ to the path.
Martin
source share