File "directory_tree.php"
Full Path: /home/analogde/www/WINDOWS/2024_PHP/directory_tree.php
File size: 646 bytes
MIME-type: text/x-php
Charset: utf-8
<?php
header('Content-Type: application/json');
function getTree($dir) {
$result = [];
$items = scandir($dir);
foreach ($items as $item) {
if ($item === '.' || $item === '..') continue;
$path = $dir . DIRECTORY_SEPARATOR . $item;
$result[$item] = is_dir($path) ? getTree($path) : null;
}
return $result;
}
$actual_path = getcwd();
//$directoryTree = getTree('/path/to/your/directory'); // Remplacez par le chemin réel de votre répertoire
$directoryTree = getTree($actual_path); // Remplacez par le chemin réel de votre répertoire
echo json_encode($directoryTree);
?>