I need to recursively traverse a certain directory and list all of the files inside of it I have found an example on the PHP website however after further searching I am not able to find a solution to my problem. The problem is that it prints out the entire path but I only want to echo out the first containing folder of the file. So for example as it sits now I get this output:
/var/www/example.com/public_html/images/6.Blah/_Original/DSC_0174.jpg
But I want it to echo:
_Original/DSC_0174.jpg
or
/_Original/DSC_0174.jpg
Here is the code I am using:
<?php
$path = realpath('/etc');
$objects = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path), RecursiveIteratorIterator::SELF_FIRST);
foreach($objects as $name => $object){
echo "$name\n";
}
?>
basename()?