ディレクトリやサブディレクトリ内のすべてのファイルを一覧表示するスクリプトを作成しようとしました。ファイルがディレクトリであるかどうかをチェックしません。コードはエラーを生成しませんが、 "Directory Listing of。"というテキストを100行生成します。私が期待していたものの代わりに。なぜこれがうまくいかないのか?PHPディレクトリのコードコードの不具合
<?php
//define the path as relative
$path = "./";
function listagain($pth)
{
//using the opendir function
$dir_handle = @opendir($pth) or die("Unable to open $pth");
echo "Directory Listing of $pth<br/>";
//running the while loop
while ($file = readdir($dir_handle))
{
//check whether file is directory
if(is_dir($file))
{
//if it is, generate it's list of files
listagain($file);
}
else
{
if($file!="." && $file!="..")
echo "<a href='$file'>$file</a><br/>";
}
}
//closing the directory
closedir($dir_handle);
}
listagain($path)
?>