Jump to content

[SOLVED] array in dropdown box


Marcos01

Recommended Posts

Hello all,

 

I would like to display folders from the server in a dropdown box.

 

This is the script I have so far:

 

$folders = (ftp_nlist($conn,"../userfiles/images/projecten"));

$recordcount = count($folders);

echo '<br />';

echo '<select name="folders">';

for($i=1; $i<$recordcount, $i ++;)

  {

    echo "<option>".$folders[$i]."</option>";

}

 

echo '</select>';

Link to comment
https://forums.phpfreaks.com/topic/121231-solved-array-in-dropdown-box/
Share on other sites

did you set the path to the directory you would like to search, and leave the *

 

?

 

It works for me...

 

I used this:

echo '<select name="folders">';
foreach(glob("../*",GLOB_ONLYDIR) as $dir){
     echo "<option>".$dir."</option>";
}
echo '</select>';

function getDirs($directory){
    $opt = array();
    foreach(glob(str_replace("//","/","$directory/*"),GLOB_ONLYDIR) as $dir){
        $opt[] = str_replace($directory,"",$dir);
    }
    return $opt;
}

$dirList = getDirs('../'); // Modify this line's folder location, don't use an asterisk.

echo '<select name="folders">';
foreach($dirList as $dir){
     echo "<option>".$dir."</option>";
}
echo '</select>';

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.