note 71649 added to function.scandir
| From: | DiegoMendesRodrigues at osu1 dot php dot net | Date: | Sun, 10 Dec 2006 04:44:53 +0000 |
| Subject: | note 71649 added to function.scandir | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-120466@lists.php.net to get a copy of this message | ||
<?
//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
----
Server IP: 66.163.161.117
Probable Submitter: 201.52.33.118
----
Manual Page -- http://www.php.net/manual/en/function.scandir.php
Edit -- https://master.php.net/note/edit/71649
Del: integrated -- https://master.php.net/note/delete/71649/integrated
Del: useless -- https://master.php.net/note/delete/71649/useless
Del: bad code -- https://master.php.net/note/delete/71649/bad+code
Del: spam -- https://master.php.net/note/delete/71649/spam
Del: non-english -- https://master.php.net/note/delete/71649/non-english
Del: in docs -- https://master.php.net/note/delete/71649/in+docs
Del: other reasons-- https://master.php.net/note/delete/71649
Reject -- https://master.php.net/note/reject/71649
Search -- https://master.php.net/manage/user-notes.php