note 20403 added to function.readdir
| From: | knight at php2 dot chek dot com | Date: | Tue, 02 Apr 2002 21:56:27 +0000 |
| Subject: | note 20403 added to function.readdir | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-28519@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";
}
?>
--
http://www.php.net/manual/en/function.readdir.php
http://master.php.net/manage/user-notes.php?action=edit+20403
http://master.php.net/manage/user-notes.php?action=delete+20403
http://master.php.net/manage/user-notes.php?action=reject+20403