class Dir_helper{
public function __construct(){
}
public function getWebdirAsArray($rootPath){
$l1 = scandir($rootPath);
foreach ($this->getFileList($rootPath) as $r1){
if ($r1['type'] == 'dir'){
if (preg_match("/\./", $r1['name'])){
$toplevel[] = $r1['name'];
} else {
if (preg_match("/\d/",$r1['name'])){
$seclevel[] = $this->getFileList($r1['name']);
}
}
}
}
foreach ($seclevel as $sl){
foreach ($sl as $cur){
$sub[] = $cur['name'];
}
}
return $result = array_merge((array)$toplevel, (array)$sub);
}
public function getFileList($dir){
$retval = array();
if(substr($dir, -1) != "/") $dir .= "/";
$d = @dir($dir) or die("getFileList: Failed opening directory $dir for reading");
while(false !== ($entry = $d->read())) {
if($entry[0] == ".") continue;
if(is_dir("$dir$entry")) {
$retval[] = array(
"name" => "$dir$entry/",
"type" => filetype("$dir$entry"),
"size" => 0,
"lastmod" => filemtime("$dir$entry")
);
} elseif(is_readable("$dir$entry")) {
$retval[] = array(
"name" => "$dir$entry",
"type" => mime_content_type("$dir$entry"),
"size" => filesize("$dir$entry"),
"lastmod" => filemtime("$dir$entry")
);
}
}
$d->close();
return $retval;
}
}