View Full Version : Read dir and sub-dir and return it to combo box (selection box, dropdown box)

07-08-2007, 04:02 AM
Good day to you all,
Here I have a code that read trough a directory and return every image to a selection box.

I would need that code to read trough a directory and return all images with in that folder and is sub-folder, all his sub-folder.

The value of it's options would be the path to this image.

<script language="JavaScript" type="text/javascript" >
function changePic(fe){
var opt_key = fe.selectedIndex;
var fileName = fe.options[opt_key].value;
return true;
<select name="image" onchange="changePic(this);">
function PGL_ConfigList($dir)
$files = array();
if($open = opendir($dir))
while(false !== ($file = readdir($open)))
if(eregi($pattern, $file) && !is_dir($file))
$files[] = $file;

$dir = "../Images/";
$list = PGL_ConfigList($dir);
foreach($list AS $file)
echo "<option value=\"../Images/$file\">$file</option>";
echo "</select>";
<img src="peuplies-1-man-small.bmp" width="100" id="noimage" align="center">

Thanks !