I want to list ONLY zip and text files in the various directories and subdirectories...
HOWEVER, this will list ALL php files and some zip files but no text files.
What is wrong?
<?php
function rec($here) {
$entries = array();
if ($handle = opendir($here)) {
while (false !== ($file = readdir($handle))) {
// This section eliminates the current and parent directories from the array
if( $file == '.' || $file == '..' ) {
continue;
} else if (is_dir($here.'/'.$file)) {
// This section adds file names to the array
array_push($entries,'<b>'.$here.'/'.$file.'/</b>');
$tmp = rec($here.'/'.$file);
foreach($tmp as $e) {
// This is supposed to add ONLY zip and txt files to the array. But it is also adding .php . I also tried $ext=substr($e,-3) and it still added the php files. What gives???
$ext = explode(".", $e);
if ($ext[1] == "zip" || $ext[1] == "txt") {
array_push($entries,$e);
}
}
} else if (is_file($here.'/'.$file)) {
// This section adds the subdirectory paths to the array I think...
array_push($entries,$here.'/'.$file);
}
}
closedir($handle);
} else {
echo "<li><b style=\"color:red\">Cannot opendir() $here</b>";
}
return $entries;
}
// The call to the recursive function....
$e = rec($_SERVER['DOCUMENT_ROOT']);
foreach($e as $x) {
echo '<li>'.$x;
}
?>
This is code from winterbeef to an earlier post I made yesterday or the day before