Jump to content

[SOLVED] Populate a listbox with files in a directory


ssailer

Recommended Posts

I need to be able to list all of the files in a directory and then put all of those files in a listbox for a user to select from.  I've been able to get the file list, but I can't figure out how to populate a list box with files from that list.  Help, please? 

This outputs the directory:

 

<?php

$dirname = "Fireworks";

$dir = opendir($dirname);

 

while(false != ($file = readdir($dir)))

{

if(($file != ".") and ($file != ".."))

{

echo("$file <br />");

}

}

?>

 

I really haven't gotten any farther than that.  I have the select box created, but it's not working at all. 

 

<select name="dlfile" id="dlfile">

<option value="<?php echo $file ?>"><?php echo $file ?></option>

</select>

 

I am extremely new to PHP (I'm a ColdFusion developer, who has done this before with CF), and I do not know how to loop through a recordset.  I know I need to use <?php

do { 

?>

but I have no idea where to put it or how to loop through the $file.

 

Thanks!

 

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.