SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Guru
    Join Date
    Nov 2004
    Location
    sweden
    Posts
    646
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    Is it possible to show a dir in a dropdown?

    I have a page for inserting a record to a db and one of the items is supposed to pick an image from a folder in a dropdown menu.

    So, what I want to do is to check the directory for filenames in a folder and show them in a dropdown menu, so the user can pick which one they want to add to the record.

    Is this possible? And how should I do it?

    I tried the following, but it didn't work at all. I just copied and modified from another file I had where I list images on a page.

    PHP Code:
    <select name="picture">
              
    <?php
    // open the current directory
    $directory opendir(".");

    // cycle thru each item in the directory
    while($dir_item readdir($directory)) {
    // display link
    if((!is_dir($dir_item)) && ($dir_item != basename($_SERVER["PHP_SELF"]))) {
    ?><option value="<?php echo $dir_item ?>" ><?php echo $dir_item ?></option>
    <?php 

      
    }
    }

    // close the directory
    closedir($directory);
    ?>
    </select>

  2. #2
    SitePoint Guru
    Join Date
    Nov 2004
    Location
    sweden
    Posts
    646
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Sorry. My fault. The code is working.
    There was an invisible code added that I didn't see until I uploaded the code here.
    So, the above works (if anyone needs it).

  3. #3
    SitePoint Zealot
    Join Date
    Jun 2006
    Posts
    133
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can probably make it a bit simpler with glob() as well


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
  •