note 51809 deleted from function.readdir by tularis
| From: | tularis@php.net | Date: | Sun, 13 May 2007 19:03:39 +0000 |
| Subject: | note 51809 deleted from function.readdir by tularis | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-126530@lists.php.net to get a copy of this message | ||
Note Submitter: twista no[at]$pam rocards $pam[dot]no de
----
I used nagash's script from below fo myself, and enhanced it.
It will now first display all folders sorted, and THEN all files sorted. Just like windows :-)
There is also a small function for hiding secret files.
Just set $rootdir to 1 in the root dir, and leave it 0 in all subdirs.
<?
$the_file_array = Array();
$the_folder_array = Array();
$handle = opendir('./');
while (false !== ($file = readdir($handle))) {
if ($file != ".") {
if (filetype($file) == "file") { $the_file_array[] = $file; } else if (filetype($file)
== "dir") {$the_folder_array[] = $file; }
}
}
closedir($handle);
sort ($the_file_array);
reset ($the_file_array);
sort ($the_folder_array);
reset ($the_folder_array);
while (list ($key, $val) = each ($the_folder_array)) {
if (($val != ".") && (!fnmatch("*.php*", $val))) {
if ((fnmatch("~*", $val)) || (fnmatch("~some_thing", $val))) {
// CASE: An outcommented file. - Syn: "~<filename>" - Exp:
"~nottobeseen.txt"
echo "** SECRET FILE **<br>";
}else{
if ($val == "..") {
if ($rootdir == "1") {
// CASE: Don't show the way upward if this is the root directory.
// Root Directory, do nothing.
}else{
// CASE: Show the ".." to go back if this is NOT the root directory.
echo '<a
href="'.$val.'/">/'.$val.'/</a><br>';
}
}else{
// CASE: All normal folders. No ".." and no ".".
echo '<a
href="'.$val.'/">/'.$val.'/</a><br>';
}
}
}
}
while (list ($key, $val) = each ($the_file_array)) {
if (($val != ".") && (!fnmatch("*.php*", $val))) {
if ((fnmatch("*~~*", $val)) || (fnmatch("~cheat_sux^hi", $val))) {
// CASE: An outcommented file. - Syn: "~<filename>" - Exp:
"~nottobeseen.txt"
echo "** SECRET FILE **<br>";
}else{
echo '<a
href="'.$val.'">'.$val.'</a><br>';
}
}
}
?>