note 36143 added to function.readdir
| From: | php at trap-door dot co dot uk | Date: | Sun, 28 Sep 2003 12:22:38 +0000 |
| Subject: | note 36143 added to function.readdir | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-57204@lists.php.net to get a copy of this message | ||
An extension to the sorted file list in a drop-down box posted by paCkeTroUTer at iprimus dot com
dot au.
Takes the directory, the "name" of the form element it produces, and optionally, a
filename. If the file name is in the list, it will be the default selection in the list.
<?
function listfiles($directory, $select_name, $selected = "") {
if ($dir = @opendir($directory)) {
while (($file = readdir($dir)) !== false) {
if ($file != ".." && $file != ".") {
$filelist[] = $file;
}
}
closedir($dir);
}
echo "<select name=\"$select_name\">";
asort($filelist);
while (list ($key, $val) = each ($filelist)) {
echo "<option value=\"$val\"";
if ($selected == $val) {
echo " selected";
}
echo ">$val</option>";
}
echo "</select>";
}
?>
Hope this helps someone.
----
Manual Page -- http://www.php.net/manual/en/function.readdir.php
Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+36143
Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+36143&report=yes
Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+36143&report=yes