SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: List dir

Hybrid View

  1. #1
    [Call me Bram] iBram007's Avatar
    Join Date
    Feb 2001
    Location
    Belgium
    Posts
    339
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    I've got a little problem. I want to list a dir with images. How do I put the whole dir in a while?
    In fact I want to create an option list with all images. like this:

    <select>
    <option value="some_image.jpg">some_image.jpg</a>
    <option value="some_image2.jpg">some_image2.jpg</option>
    </select>

    do you understand? yes?
    oh great, and how do I do this?

  2. #2
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I would first loop through the folder and place all the filenames in an array, then I wouls simply loop through the array and put each filename into the drop down list

    PHP Code:
    <?
    $dir 
    dir("/path/to/images/folder");
    while(
    $file $dir->read()) {
        if ((
    $file != ".") && ($file != "..")) {
            
    $files[] = $file;
            }
        }
    ?>
    <select name="images">
    <?
    foreach($files as $key => $val) {
    ?>
    <option value="<?=$val?>"><?=$val?></option>
    <?
        
    }
    ?>

    </select>
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  3. #3
    [Call me Bram] iBram007's Avatar
    Join Date
    Feb 2001
    Location
    Belgium
    Posts
    339
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Freddy


Bookmarks

Posting Permissions

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