...

View Full Version : Read dir and sub-dir and put image in dropdown box



Peuplarchie
07-17-2007, 12:28 AM
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.



<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

NancyJ
07-17-2007, 10:25 AM
works fine for me - what is the problem? Are you getting an error of some sorts? Perhaps the problem is the directory that you're giving it.

Peuplarchie
07-17-2007, 01:53 PM
Yes it's working fine, I need it to look into that same directory and his sub-directory to find all the images within the folder and his sub folder.

NancyJ
07-17-2007, 01:58 PM
I see, well this should be what you're looking for then
http://www.codingforums.com/showthread.php?t=71882



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum