forked from gmaro4d/coreI5
/
filelist.php
35 lines (29 loc) · 1004 Bytes
/
filelist.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<?
function ListFolder($path) {
//using the opendir function
$dir_handle = @opendir($path) or die("Unable to open $path");
//Leave only the lastest folder name
$dirname = end(explode("/", $path));
echo '<ul>';
//display the target folder.
echo '<li><a href="'.$dirname.'" class="folder">'.$dirname.'</a>';
echo '<ul>';
while (false !== ($file = readdir($dir_handle))) {
if ($file != "." && $file != "..") {
if (is_dir($path . "/" . $file)) {
//Display a list of sub folders.
ListFolder($path . "/" . $file);
} else {
//Display a list of files.
echo '<li><a href="'.$file.'">'.$file.'</a></li>';
}
}
}
echo "</ul>";
echo "</li>";
echo "</ul>";
//closing the directory
closedir($dir_handle);
}
ListFolder("./files");
?>