01 <?php
02
03 // function read & list directory
04 // returns directories which have $filter as prefix
05 function read_dir($root, $filter)
06 {
07 $output = '
08 <ul>';
09
10 $root_dir = opendir($root);
11 while($file_file = readdir($root_dir))
12 {
13 if(is_dir($root.'/'.$file_file ) // remove this if you want to show files too
14 && $file_file != '.'
15 && $file_file != '..'
16 && substr($file_file, 0, strlen($filter)) == $filter)
17 {
18 $mtime = filemtime($root.'/'.$file_file);
19 $array = array('_' => ' ',$filter => '');
20 $thefile = strtr($file_file ,$array);
21 $output .= '
22 <li>
23 <a href="'.$root.'/'.$file_file.'">'.$thefile .'</a>
24 (last modified on '.date('D d M Y g:i A', $mtime).')
25 </li>';
26 }
27 }
28 $output .= '
29 </ul>';
30 }
31
32 //example use of the filter option
33 $superuser = true;
34 $directory_to_scan = '.';
35
36 if($superuser)
37 {
38 // show list of all directories with "private_" as prefix
39 read_dir($directory_to_scan, 'private_');
40 }else{
41 // show list of all directories with "public_" as prefix
42 read_dir($directory_to_scan, 'public_');
43 }
44
45 ?>