note 51809 added to function.readdir
| From: | twistano | Date: | Mon, 11 Apr 2005 21:18:05 +0000 |
| Subject: | note 51809 added to function.readdir | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-87862@lists.php.net to get a copy of this message | ||
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>';
}
}
}
?>
----
Manual Page -- http://www.php.net/manual/en/function.readdir.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+51809
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+51809&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+51809&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+51809&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+51809&report=yes&reason=useless
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+51809&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+51809&report=yes
Search -- http://master.php.net/manage/user-notes.php