note 71649 deleted from function.scandir by nlopess

From: Date: Sun, 10 Dec 2006 11:20:32 +0000
Subject: note 71649 deleted from function.scandir by nlopess
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-120475@lists.php.net to get a copy of this message
Note Submitter: Diego Mendes Rodrigues ---- <? //Simple and useful function to make a select with files of a directory //Diego Mendes Rodrigues - www.drsolutions.com.br function select_file($dir="./",$name="mypics",$selected="",$css="") { $drReturn = "\n<select name='" . $name . "' " . (!empty($css) ? "class='" . $css . "'": "") . ">\n"; $drReturn .= "<option value=''>Select...</option>\n"; if (is_dir($dir)) { $files = scandir($dir); for ( $i = 0; $i < count($files); $i++ ) { if ( $files[$i] == ".." || $files[$i] == "." ) continue; else $drReturn .= "<option value='" . $files[$i] . "' " . (strtolower($files[$i]) == strtolower($selected)? "selected":""). ">" . $files[$i] . "</option>\n"; } } $drReturn .= "</select>\n"; return $drReturn; } //Examples //-------- //Simple echo select_file("./photos"); //Set the name of select to 'photo' echo "<br><br>" . select_file("./photos","photo"); //Set the name of select to 'photo' and select file 'DSC010034.JPG' echo "<br><br>" . select_file("./photos","photo","DSC010034.JPG"); //Set the name of select to 'photo', select file 'DSC010034.JPG' and apply the css style 'form300' echo "<br><br>" . select_file("./photos","photo","DSC010034.JPG","form300"); ?> Get it: http://www.drsolutions.com.br/exemplos/select_file_example.zip

« previous php.notes (#120475) next »