/
al.anatolyev
/
web4stud
Обзор
Документация
Войти
/
al.anatolyev
/
web4stud
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
samples/index.php
60 строк
2 KB
aag
rawdata needs to be fetched
26 мар 2026, 14:57
26 мар 2026, 14:57
9edf541
Код
Авторство
О чём код?
<?php /** * Recursively lists files and directories in a given path as an HTML unordered list. * * @param string $path The directory path to scan. */ function listFolderFiles($path) { // Use scandir to get all files and directories, excluding '.' and '..' $files = array_diff(scandir($path), array('.', '..')); echo '<ul>'; foreach ($files as $file) { $filePath = $path . DIRECTORY_SEPARATOR . $file; if (is_dir($filePath)) { // If it's a directory, display as a list item with a "folder" class echo '<li class="folder"><a href="' . htmlentities($file).'">'. htmlentities($file).'/</a>'; // Recursively call the function for subdirectories listFolderFiles($filePath); echo '</li>'; } else { // If it's a file, display as a simple list item with a "file" class // You can add logic here to determine file extensions for different icons echo '<li class="file">' . htmlentities($file) . '</li>'; } } echo '</ul>'; } // Specify the starting directory (e.g., the current directory) $startDir = '.'; ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>File Tree View</title> <style> /* Basic CSS for visual representation */ ul { list-style-type: none; } .folder { font-weight: bold; } .file { font-weight: normal; margin-left: 20px; } /* Add CSS to include folder/file icons */ .folder::before { content: ''; } .file::before { content: ''; } </style> </head> <body> <h3>File Structure of `<?php echo htmlentities($startDir); ?>`</h3> <div id="fileTreeContainer"> <?php listFolderFiles($startDir); ?> </div> </body> </html>