public static function scanDirs($path, $onlyLevel = false, $lvl = 0)
    {
        static $res;

        if ($lvl == 0) {
            $res = [];
        }

        if (!is_dir($path)) {
            return [];
        }

        if (substr($path, -1) == '/') {
            $path = substr($path, 0, -1);
        }
        $dir_base_length = strlen(DIR_BASE) - 1;

        foreach (array_diff(scandir($path), ['.', '..']) as $f) {
            if (is_dir($path . '/' . $f)) {
                if (!$onlyLevel) $res[] = [
                    'path_url' => substr($path, $dir_base_length),
                    'path'     => $path,
                    'name'     => $f,
                    'full'     => $path . '/' . $f,
                    'fs'       => 0,
                    'type'     => 'dir'
                ];
                self::scanDirs($path . '/' . $f, $onlyLevel, $lvl + 1);
            } elseif ($onlyLevel) {
                $res[] = $path . '/' . $f;
            } else {
                $res[] = [
                    'path_url' => substr($path, $dir_base_length),
                    'path'     => $path,
                    'name'     => $f,
                    'full'     => $path . '/' . $f,
                    'fs'       => filesize($path . '/' . $f),
                    'type'     => 'file'
                ];
            }
        }

        if ($lvl == 0) {
            return $res;
        }

        return [];
    }
public static function scanDirs($path, $onlyLevel = false, $lvl = 0)
    {
        static $res;

        if ($lvl == 0) {
            $res = [];
        }

        if (!is_dir($path)) {
            return [];
        }

        if (substr($path, -1) == '/') {
            $path = substr($path, 0, -1);
        }
        $dir_base_length = strlen(DIR_BASE) - 1;

        foreach (array_diff(scandir($path), ['.', '..']) as $f) {
            if (is_dir($path . '/' . $f)) {
                if (!$onlyLevel) $res[] = [
                    'path_url' => substr($path, $dir_base_length),
                    'path'     => $path,
                    'name'     => $f,
                    'full'     => $path . '/' . $f,
                    'fs'       => 0,
                    'type'     => 'dir'
                ];
                self::scanDirs($path . '/' . $f, $onlyLevel, $lvl + 1);
            } elseif ($onlyLevel) {
                $res[] = $path . '/' . $f;
            } else {
                $res[] = [
                    'path_url' => substr($path, $dir_base_length),
                    'path'     => $path,
                    'name'     => $f,
                    'full'     => $path . '/' . $f,
                    'fs'       => filesize($path . '/' . $f),
                    'type'     => 'file'
                ];
            }
        }

        if ($lvl == 0) {
            return $res;
        }

        return [];
    }
public static function scanDirs ( $ path , $ onlyLevel = false , $ lvl = 0 ) { static $ res ; if ( $ lvl == 0 ) { $ res = [ ] ; } if ( ! is_dir ( $ path ) ) { return [ ] ; } if ( substr ( $ path , - 1 ) == '/' ) { $ path = substr ( $ path , 0 , - 1 ) ; } $ dir_base_length = strlen ( DIR_BASE ) - 1 ; foreach ( array_diff ( scandir ( $ path ) , [ '.' , '..' ] ) as $ f ) { if ( is_dir ( $ path . '/' . $ f ) ) { if ( ! $ onlyLevel ) $ res [ ] = [ 'path_url' => substr ( $ path , $ dir_base_length ) , 'path' => $ path , 'name' => $ f , 'full' => $ path . '/' . $ f , 'fs' => 0 , 'type' => 'dir' ] ; self :: scanDirs ( $ path . '/' . $ f , $ onlyLevel , $ lvl + 1 ) ; } elseif ( $ onlyLevel ) { $ res [ ] = $ path . '/' . $ f ; } else { $ res [ ] = [ 'path_url' => substr ( $ path , $ dir_base_length ) , 'path' => $ path , 'name' => $ f , 'full' => $ path . '/' . $ f , 'fs' => filesize ( $ path . '/' . $ f ) , 'type' => 'file' ] ; } } if ( $ lvl == 0 ) { return $ res ; } return [ ] ; }
Returns the directory and its content data recursively
@param string $path - Path to directory from where to start
@param bool   $onlyLevel
@param int    $lvl  - level
@return array with content
Returns the directory and its content data recursively