note 20403 rejected from function.readdir by sander
| From: | sander@php.net | Date: | Sat, 06 Apr 2002 19:17:06 +0000 |
| Subject: | note 20403 rejected from function.readdir by sander | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-28761@lists.php.net to get a copy of this message | ||
If you want to grab all the files in the current directory and list them along with creating valid
links incase the php file is in a subfolder you can do the following:
<?
// list.php
// This file will grab the list of files in the current directory
// and create links so that people may view them. There
// is an option called $exclude_files that will allow you to
// exclude any files you do not wish to be displayed.
// Currently there are two. One for the name of this
// file and another as an example.
// Copyright (c) 2002 - Phil Brault
// <knight at scriptparadise dot net>.
$path = getcwd();
$dir = opendir($path);
$exclude_files = array( "list.php", "phpinfo.php" );
while($item = readdir($dir))
{
if($item == "." || $item == ".." || $item == $exclude_files[0] || $item ==
$exclude_files[1]) continue;
$files_list[count($files_list)] = $item;
}
clearstatcache();
closedir($dir);
sort($files_list);
while (list($key,$val) = each($files_list))
{
$link_file_path = ereg_replace($path, ".", $path);
echo "<p><a
href=\"$link_file_path/$val\">$val</a><p>\n";
}
?>