Skip to content
Snippets Groups Projects
get-filestructure-service.php 866 B
Newer Older
<?php
    include 'config.php';

    $fileTree = scanDirRec($assetsDir.'/docs');
    exit(json_encode($fileTree, JSON_UNESCAPED_SLASHES));

    function scanDirRec($path){
        global $assetsDir;

        $currentDir = [];
        if (file_exists($path)){
            $files = scandir($path);
        } else {
            $files = [];
        }
        foreach ($files as $key => $value){
            if ($value != '..' && $value != '.'){
                $file['name'] = str_replace('.json', '', $value);
                $file['id'] = str_replace($assetsDir.'/docs', '', $path).'/'.$value;

                if (is_dir($path.'/'.$value)){
                    $file['children'] = scanDirRec($path.'/'.$value);
                }
                array_push($currentDir, $file);
                unset($file);
            }
        }
        return $currentDir;
    }