Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Feb 2006
    Posts
    262
    Thanks
    23
    Thanked 1 Time in 1 Post

    Post Read dir and sub-dir and put image in dropdown box

    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.

    PHP Code:
    <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

  • #2
    Senior Coder NancyJ's Avatar
    Join Date
    Feb 2005
    Location
    Bradford, UK
    Posts
    3,174
    Thanks
    19
    Thanked 66 Times in 65 Posts
    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.

  • #3
    Regular Coder
    Join Date
    Feb 2006
    Posts
    262
    Thanks
    23
    Thanked 1 Time in 1 Post
    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.

  • #4
    Senior Coder NancyJ's Avatar
    Join Date
    Feb 2005
    Location
    Bradford, UK
    Posts
    3,174
    Thanks
    19
    Thanked 66 Times in 65 Posts
    I see, well this should be what you're looking for then
    http://www.codingforums.com/showthread.php?t=71882


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •