note 66462 deleted from function.readdir by bjori
| From: | bjori@php.net | Date: | Tue, 23 May 2006 13:37:03 +0000 |
| Subject: | note 66462 deleted from function.readdir by bjori | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-111864@lists.php.net to get a copy of this message | ||
Note Submitter: harman_tom at hotmail dot com
----
I am new to PHP and can't seem to figure out how to only show certain file types in the
following script.
<code>
<?php
$DirectoriesToScan = array(realpath('.'));
$DirectoriesScanned = array();
while (count($DirectoriesToScan) > 0) {
foreach ($DirectoriesToScan as $DirectoryKey => $startingdir) {
if ($dir = @opendir($startingdir)) {
while (($file = readdir($dir)) !== false) {
if (($file != '.') && ($file != '..')) {
$RealPathName = $file;
if (is_dir($RealPathName)) {
if (!in_array($RealPathName, $DirectoriesScanned) && !in_array($RealPathName,
$DirectoriesToScan)) {
$DirectoriesToScan[] = $RealPathName;
}
} elseif (is_file($RealPathName)) {
$FilesInDir[] = $RealPathName;
}
}
}
closedir($dir);
}
$DirectoriesScanned[] = $startingdir;
unset($DirectoriesToScan[$DirectoryKey]);
}
}
$FilesInDir = array_unique($FilesInDir);
sort($FilesInDir);
foreach ($FilesInDir as $filename) {
echo ("<a href=$filename>$filename</a><br>");
}
?>
</code>