Forum Moderators: coopster
<?php
function listFolders(){
$path = glob("*",GLOB_ONLYDIR); //the double \\ is not a typo you
//have to escape it
//if the path cannot be found
if(!($path)){
echo("The specified path could not be found.");
return;
}//if
//the path is valid
else{
foreach($path as $i){
echo $i;
echo "<br>";
}//foreach
}//else
}//populateDropdown
?>
<?php echo listFolders() ?>
$count = 0;
while (false !== ($file = readdir($handle))) {
echo "$file\n";
$count++;
if($count == 10) {
break;
}
}
<?php
function listFolders($path,$recurse_limit=null){
$counter=0;
$dirlist=$dir_errors=null;
//if the path cannot be found
if(! is_dir($path)){
return Array (null,"The specified path could not be found.");
}//if
//the path is valid
else{
foreach($path as $i){
$counter++;
$dirlist .= "<li>$i</li>\n"; // Retentive about semantics is Padawan
if ($recurse_limit and ($counter >= $recurse_limit)) {
break;
}
}//foreach
}//else
return Array($dirlist,$dir_errors);
}//listFolders
?>
//
<?php
// assuming GLOB_ONLYDIR is a constant
$dir_limit = 10;
list($dirs,$errors) = listFolders(GLOB_ONLYDIR,$dir_limit);
echo ($errors)?"Error: $errors":"<ul>$dir</ul>";
?>