Read dir and sub-dir and put image in dropdown box
Posted: Mon Jul 16, 2007 5:28 pm
Good day to you all,
I have searched , tried, many way but I can't figure how to make that piece of code look into all the sub-folder and take show all image file in a drop down box.
Can somebody help me with this ?
I'm on php 4, on window 2003
I have searched , tried, many way but I can't figure how to make that piece of code look into all the sub-folder and take show all image file in a drop down box.
Code: Select all
<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);">
<option>[Choisir une image]</option>
<?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 = "Upload/";
$list = PGL_ConfigList($dir);
foreach($list AS $file)
{
echo "<option value=\"Upload/$file\">$file</option>";
}
echo "</select>";
?>Can somebody help me with this ?
I'm on php 4, on window 2003