如何获取文件名?

Jam*_*mes 5 php directory file

就像,我们有文件夹/images/,里面有一些文件.

和脚本 /scripts/listing.php

我们怎样才能获得文件夹/images/中所有文件的名称listing.php

谢谢.

Wou*_*elo 8

<?php

if ($handle = opendir('/path/to/files')) {
    echo "Directory handle: $handle\n";
    echo "Files:\n";

    /* This is the correct way to loop over the directory. */
    while (false !== ($file = readdir($handle))) {
        echo "$file\n";
    }

    /* This is the WRONG way to loop over the directory. */
    while ($file = readdir($handle)) {
        echo "$file\n";
    }

    closedir($handle);
}
?>
Run Code Online (Sandbox Code Playgroud)

请参阅:readdir()