문제

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";
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top