Zend - The PHP Company




Forms

Add Code


Dir 2 Box  

Type: code fragment
Added by: wibi
Entered: 05/07/2001
Last modified: 09/12/2007
Rating: ***** (3 votes)
Views: 10374
This function will read a directory and put the result into a listbox. So you can choose a file from that listbox.


<?
/********************************************************************
*    drop-down-menu - form field function.
*    function that read directory content and 
*    return the result list as drop-down-menu
*   Syntax :
*        - string dir2box(string path, string name, string selected-file);
*
*    Copyright (C) 2001 Wibisono Sastrodiwiryo. 
*       This program is free software licensed under the 
*       GNU General Public License (GPL).
*
*   CyberGL => Application Service Provider
*   http://www.cybergl.co.id
*    office@cybergl.co.id
*
*   $Id: dir2box.php3,v 0.1 2001/07/5 19:42:20 wibi Exp $ 
*********************************************************************/

function dir2box($path$name$default="") {
    
$result="<select name="$name" size=1>n";
     
$handle=opendir("$path");
     while (
$file readdir($handle)) {
        if (
$file == $default) {$selected="selected";} else {$selected="";}
        if (
$file != "." and $file !="..") {$result.="<option value="$file$selected>$file</option>n";}
     }
     
closedir($handle);
    
$result.="</select>n";
return 
$result;
}
?>


Usage Example


<?
require("dir2box.php3");
$default="index.php3";
$path="/home/cybergl.co.id/htdocs";
?>
<form>
<p>
Files : 
<?
echo dir2box($path"directory"$default);
?>
<p>
</form>


Rate This Script





Search



This Category All Categories