Results 1 to 4 of 4

Thread: How to display a listbox inside a directory

  1. #1
    Join Date
    Aug 2009
    Posts
    59

    How to display a listbox inside a directory

    Here is my problem. I have a form of update, and would like to display the names of the images contained in a folder all in a listbox. That way I could select the image I want through the listbox and do a little update. But as my knowledge is concerned, php is quite limited (sql insert, update and delete). So how can I display a listbox inside a directory?

    PHP Code:
    <select name="listDir">
    <?php
    $rep 
    ='upload/';
    if (!
    is_dir ($rep)) {
        echo 
    'Error, '$dir,' is not a valid directory';
        exit;
    }
    $dir opendir ($rep);
            while (
    false !== ($file readdir ($dir))) {
                if (
    $file !== '..' && $file !== '.') {
                    echo 
    '<option value="',$file,'">',$file,'</option>';
                }
            }
    ?>
    </select>

  2. #2
    Join Date
    May 2008
    Posts
    2,297

    Re: How to display a listbox inside a directory

    Tries more or less it, I do not know if it will work the first time, trying to understand/debug (no wizard in there) and if something is wrong does not hesitate to ask further questions:

    PHP Code:
    <select name="image">
    <?php
    $d 
    dir("/myaccount/whichcontains/theimages" );
    while (
    false !== ($entry $d->read()))
    {
       if (
    '.' !== $entry && '..' != $entry)
       {
       
    ?>
          <option value="<?php echo $entry?>"><?php echo $entry?></option>
       <?php
       
    }
    }
    $d->close();
    ?>
    </select>

  3. #3
    Join Date
    Aug 2009
    Posts
    59

    Re: How to display a listbox inside a directory

    If so, its the penalty, beginning before the huge eternal great php, I look and try to understand, but it is not working or I think I missed something. I need little more explanation on this.

  4. #4
    Join Date
    May 2008
    Posts
    2,297

    Re: How to display a listbox inside a directory

    The method I gave you does the same thing that you have found, but object-oriented.

    Instead of using opendir () which returns you $dir, use readdir() on it and end closedir(), you use the dir() which returns you an object of type Directory.

    Then you use the object methods directly.

    PHP Code:
    $dir opendir($rep); 
    $entry readdir($rep); 
    closedir($rep);

    $d dir($rep); 
    $entry $d->read();
    $d->close(); 

Similar Threads

  1. Replies: 2
    Last Post: 28-05-2012, 12:33 PM
  2. How to create ListBox in VB.net?
    By MarceloQuad in forum Software Development
    Replies: 4
    Last Post: 22-01-2010, 08:44 PM
  3. C# Listbox control
    By abhinavm in forum Software Development
    Replies: 2
    Last Post: 07-08-2009, 11:01 PM
  4. Replies: 3
    Last Post: 01-07-2009, 03:46 PM
  5. To display webpage inside another webpage
    By Faakhir in forum Technology & Internet
    Replies: 3
    Last Post: 24-03-2009, 10:59 AM

Tags for this Thread

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
  •  
Page generated in 1,713,971,959.19839 seconds with 16 queries