Frage

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>'; 
    } 
    ?> 
War es hilfreich?

Lösung

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.

Andere Tipps

Surely you can just use basename()

echo basename($filename) . "\n";
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top