...

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



Peuplarchie
07-08-2007, 05: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;
document.noimage.src=fileName;
return true;
}
</script>
<select name="image" onchange="changePic(this);">
<?php
function PGL_ConfigList($dir)
{
$pattern="\.(jpg|jpeg|png|gif|bmp)$";
$files = array();
if($open = opendir($dir))
{
while(false !== ($file = readdir($open)))
{
if(eregi($pattern, $file) && !is_dir($file))
{
$files[] = $file;
}
}
}
closedir($open);

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





Thanks !



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum