ディレクトリのファイル一覧を取得(全階層)

/*
* 指定したディレクトリのファイル一覧を取得する
*/
class getDirList{
public $dir=array();
public $file=array();

public function getDirList($trgDir){
if ($dir = opendir($trgDir)) {
while *1 !== false) {
if ($file != "." && $file != "..") {
if(is_dir($trgDir.'/'.$file)){
array_push($this->dir, $trgDir.'/'.$file);
$this->getDirList($trgDir.'/'.$file);
}else{
array_push($this->file, $trgDir.'/'.$file);
}
}
}
closedir($dir);
}
}
/*
* 取得したリストを表示
* @param string type dir:ディレクトリのみ表示 file:ファイル none:両方
* @return void
*/
public function showList($type=""){
$array = array();
switch ($type){
case "dir":
$array = $this->dir;
break;
case "file":
$array = $this->file;
break;
default:
$array = array_merge($this->dir,$this->file);
break;
}

foreach($array as $value){
echo $value."
";
}
}
}

*1:$file = readdir($dir