1 <?php/*
2 $Id: ldir.php,v 1.4 2007/12/10 20:07:24 streamkid Exp $
3 */
4
5 /* USAGE:
6 * $var = array (’foo’); where foo is the filesystem relative path where the files are relatively to script execution path. if you want the same (.) dir, ”, else the dir, ie ‘images’
7 * ldir(’filesystem path’, 0, $var, ‘client relative path’); where client relative path is how it’s seen from outsie, ie apache. eg /~streamkid (WITHOUT trailing slash)
8 * $ignore = array (”); any folders or directories you don’t want to list
9 */
10 ?>
11
12 <?php
13 function ldir($path, $level, $struct, $abs) {
14 $ignore = array (‘cgi-bin‘, ‘.‘, ‘..‘, ‘.htaccess‘, ‘.t3hdirectives‘, ‘Thumbs.db‘, ‘webarchive‘);
15 $dh = @opendir($path);
16 while (false !== ($file = readdir($dh))) {
17 if (!in_array($file, $ignore)) {
18 $spaces = str_repeat(‘ ‘, ($level*4));
19 $struct[$level] = $abs;
20 $url = ”;
21 if ($level > 0) {
22 for ($i = 0; $i <= $level; $i += 1) {
23 $url .= $struct[$i];
24 $url .= ‘/‘;
25 }
26 $url .= $file;
27 }
28 else {
29 $url .= $abs;
30 $url .= ‘/‘;
31 $url .= $file;
32 }
33 if (is_dir(“$path/$file“)) {
34 echo “$spaces + $file<br/>\n“;
35 $dir .= ‘/‘;
36 $dir .= $file;
37 ldir (“$path/$file“, ($level + 1), $struct, $file);
38 }
39 else {
40 echo “$spaces - <a href=\”$url\”>$file</a> “;
41 echo round(filesize(“$path/$file“)/1024, 2);
42 echo “ kB<br/>\n“;
43 }
44 }
45 }
46 closedir($dh);
47 }
48
49 ?>
I made this ’cause apache’s fancy-indexing wasn’t enough. This shows all files and subfolders and subfiles of a folder, in a tree structure. See it live here:
http://streamkid.net/~streamkid
Post a Comment