Jump to content

[SOLVED] Populate a drop down list with directory contents


swamp

Recommended Posts

Elo,

 

I've done a bit of searching around for this but haven't got anywhere...

 

I've got a directory called user-biogs each is titled with the username (eg) john white.txt is John White's user 'biog'.

 

I want to be able to populate a drop down list with all the files in the user-biogs directory for a form. Also preferabley there would be no .txt extension.

 

Any help/advice much appreciated!

 

Cheers

Try a similiar approach:

 

<form method="post" name="myform" id="myform" action="">
    <select name="names" id="names">
    <?php
    foreach(glob('*.txt') as $file){ //loop through all .txt files
         $file = substr($file, 0, strrpos($file, '.')); //strip the .txt extension
         echo "<option value='{$file}'>{$file}</option>"; //print the option
    }
    ?>
    </select>
</form>

 

@thorpe, except accessing files in http, which should show name%20surname, I don't see problems with spaces.

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.