note 36143 deleted from function.readdir by tularis

From: Date: Sun, 13 May 2007 19:06:35 +0000
Subject: note 36143 deleted from function.readdir by tularis
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-126550@lists.php.net to get a copy of this message
Note Submitter: php at trap-door dot co dot uk ---- 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.

« previous php.notes (#126550) next »