File "explorateur01.php"

Full Path: /home/analogde/www/Analyse/explorer/explorateur01.php
File size: 2.63 KB
MIME-type: text/x-php
Charset: utf-8

<?php
function scanDirectory($directory) {
    $result = [];
    $files = scandir($directory);
    foreach ($files as $file) {
        if ($file !== '.' && $file !== '..') {
            $path = $directory . DIRECTORY_SEPARATOR . $file;
            if (is_dir($path)) {
                $result[] = [
                    'name' => $file,
                    'type' => 'directory',
                    'children' => scanDirectory($path)
                ];
            } else {
                $result[] = [
                    'name' => $file,
                    'type' => 'file'
                ];
            }
        }
    }
    return $result;
}

function displayTree($tree, $level = 0) {
    foreach ($tree as $item) {
        echo '<div class="tree-item" style="margin-left: ' . ($level * 20) . 'px;">';
        echo '<span class="toggle" onclick="toggleTree(this)">' . ($item['type'] === 'directory' ? '+' : '') . '</span>';
        echo '<span class="name">' . htmlspecialchars($item['name']) . '</span>';
        if (isset($item['children'])) {
            echo '<div class="tree-children" style="display: none;">';
            displayTree($item['children'], $level + 1);
            echo '</div>';
        }
        echo '</div>';
    }
}

$directory = "http://analog-design.net/2024_PHP" ; ///getcwd(); //'path/to/your/directory'; // Remplacez par le chemin de votre répertoire

$directory = "/analogde/2024_PHP" ; ///getcwd(); //'path/to/your/directory'; // Remplacez par le chemin de votre répertoire

$directory = getcwd(); //'path/to/your/directory'; // Remplacez par le chemin de votre répertoire

$directory = "/home/analogde/www/2024_PHP/2024_PHP_26_10_2024";

echo $directory;

$tree = scanDirectory($directory);
?>

<!DOCTYPE html>
<html lang="fr">
<head>
    <meta charset="UTF-8">
    <title>Tree View</title>
    <style>
        .tree-item {
            cursor: pointer;
        }
        .toggle {
            display: inline-block;
            width: 20px;
            text-align: center;
        }
        .name {
            display: inline-block;
        }
        .tree-children {
            margin-left: 20px;
        }
    </style>
    <script>
        function toggleTree(element) {
            const children = element.nextElementSibling.nextElementSibling;
            if (children.style.display === 'none') {
                children.style.display = 'block';
                element.textContent = '-';
            } else {
                children.style.display = 'none';
                element.textContent = '+';
            }
        }
    </script>
</head>
<body>
    <div class="tree-view">
        <?php displayTree($tree); ?>
    </div>
</body>
</html>