function GetDirs($dir)
{
    $dirfiles1 = scandir($dir);
    //Add files and details to new array
    foreach ($dirfiles1 as $dirfile) {
        if ($dirfile != '.' && $dirfile != '..') {
            $dir1 = explode('./', $dir);
            if ($dir1[1] != null) {
                $dir1 = $dir1[1] . '/';
            } else {
                $dir1 = '';
            }
            if (is_dir($dir . '/' . $dirfile)) {
                foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir1 . $dirfile)) as $file) {
                    $filesize += $file->getSize();
                }
            } else {
                $filesize = filesize($dir1 . $dirfile);
            }
            $filesize = round($filesize, 2);
            $filedate = date('Y-m-d H:i:s', filectime($dir1 . $dirfile));
            if (!in_array('/' . $dir1 . $dirfile, $GLOBALS['blacklist'])) {
                array_push($GLOBALS['dirfiles'], array($dirfile, $dir, $filesize, $filedate));
            }
            if (is_dir($dir . '/' . $dirfile)) {
                GetDirs($dir . '/' . $dirfile);
            }
        }
    }
}
function GetDirs($path, $type)
{
    $ret = $sort = array();
    $files = listDirectory(fixPath($path), 0);
    foreach ($files as $f) {
        $fullPath = $path . '/' . $f;
        if (!is_dir(fixPath($fullPath)) || $f == '.' || $f == '..') {
            continue;
        }
        $tmp = getFilesNumber(fixPath($fullPath), $type);
        $ret[$fullPath] = array('path' => $fullPath, 'files' => $tmp['files'], 'dirs' => $tmp['dirs']);
        $sort[$fullPath] = $f;
    }
    natcasesort($sort);
    foreach ($sort as $k => $v) {
        $tmp = $ret[$k];
        echo ',{"p":"' . mb_ereg_replace('"', '\\"', $tmp['path']) . '","f":"' . $tmp['files'] . '","d":"' . $tmp['dirs'] . '"}';
        GetDirs($tmp['path'], $type);
    }
}