Listing files in Directory without the path
-
26-05-2021 - |
質問
Im using the following to list the files in a directory in a intranet site I am making. The problem is that is is also listing the path to the file too, does anyone know what im doing wrong ?. thanks :-)
<?php
foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator('./customer-files/28734f6d045f8a5a93.18936710')) as $filename)
{
echo '<p>';
echo "$filename\n";
echo '</p>';
}
?>
解決
You know the path you're passing, just use either:
str_replace($path,'',$filename);
or
substr($filename,strlen($path));
If you don't want ANY PATH in there, you can just get the filename with $filename->getFilename();
however, that will lead to confusion, as subdirectories won't be visible.
他のヒント
Surely you can just use basename()
echo basename($filename) . "\n";
所属していません StackOverflow