title: PHP - Listing all directories and sub-directories recursively in drop down menu
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/2524151/php-get-all-subdirectories-of-a-given-directory">PHP Get all subdirectories of a given directory</a>  </p>
  </blockquote>
  
  
  
  <p>I want a drop down menu to show all sub-directories in <code>./files/$userid/</code> not just the main folder. For example:    <code>/files/$userid/folder1/folder2/</code></p>
  
  <p>My current code is:</p>
  
  <p>HTML:</p>
  
  <pre><code>&lt;select name="myDirs"&gt;
  &lt;option value=""  selected="selected"&gt;Select a folder&lt;/option&gt;
  </code></pre>
  
  <p>PHP:</p>
  
  <pre><code>if (chdir("./files/" . $userid)) {
  
         $dirs = glob('*', GLOB_ONLYDIR);
         foreach($dirs as $val){
            echo '&lt;option value="'.$val.'"&gt;'.$val."&lt;/option&gt;\n";
         }        
          } else {
         echo 'Changing directory failed.';
  }
  </code></pre>