SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Jun 2000
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    In PHP3 how can I get the listings of a dir into an array?

    I know it has something to do with readdir() and such, I just can't get the looping to work right.

    Thanks,

    -Matt

  2. #2
    SitePoint Evangelist
    Join Date
    May 2000
    Location
    Canada
    Posts
    533
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    <?
    $asdf = dir("whatever")
    $ar = array();

    while($file = readdir($asdf))
    {
    $ar[count($ar)-1] = $file;
    }

    ?>

    that should do the trick

    ----------------------
    my PHP host

  3. #3
    SitePoint Member
    Join Date
    Jun 2000
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Works like a charm!

    Thank you very much,

    -Matt

  4. #4
    SitePoint Evangelist
    Join Date
    May 2000
    Location
    Canada
    Posts
    533
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    anytime.. glad to be of help


    ----------------------
    my PHP host -- your php host too!

  5. #5
    SitePoint Author Kevin Yank's Avatar
    Join Date
    Apr 2000
    Location
    Melbourne, Australia
    Posts
    2,571
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Not to show you up, Vinay, but here's a slightly simpler version that works exactly the same. Could be faster for large directories.

    <?
    $asdf = dir("whatever");
    $ar = array();
    while($file = readdir($asdf))
    {
    $ar[] = $file;
    }
    ?>


    ------------------
    -Kevin Yank.
    http://www.SitePoint.com/
    Helping Small Business Grow Online!


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
  •