SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Member
    Join Date
    Apr 2002
    Location
    Pleasant Hill, CA
    Posts
    20
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    getting certain files from a directory

    Ok ... I'm pretty new to php and have racked my little brain and searched the forums to no avail.

    I want to get a list of file names containing certain text. I have a directory that contains images. xxx.full.jpg and xxx.thumb.jpg.

    I want to get an array containing only the files that have thumb in the name.

    How do I do that?

    I can get a list of all files easy enough, I just don't know how to sort out only the ones that I want.

    Thanks,
    Rusty

  2. #2
    PHP manual bot bronze trophy Gaheris's Avatar
    Join Date
    Oct 2003
    Location
    Germany
    Posts
    2,195
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hope this helps.
    PHP Code:
    $images = array();
    $d dir('directory/');
    while (
    false !== ($entry $d->read())) {
        if (
    $entry == '.' || $entry == '..') continue;
        if (
    stristr($entry'thumb')) $images[] = $entry;
    }
    $d->close();

    print_r($images); 

  3. #3
    SitePoint Member
    Join Date
    Apr 2002
    Location
    Pleasant Hill, CA
    Posts
    20
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That's perfect!!!

    Now I can put in a random thumbnail.

    http://www.adtscuba.com/after/

    Thanks,
    Rusty

  4. #4
    SitePoint Member
    Join Date
    Apr 2002
    Location
    Pleasant Hill, CA
    Posts
    20
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok ... I got all my code to work and I think I even understand most of it (sort of).

    One question ...

    if ($entry == '.' || $entry = '..') continue;

    Am I right that this looks at the directory listing and just says keep going? And I guess ... what would cause this to fail if this line was not there?

    Just trying to understand it all ...

    Thanks,
    Rusty

  5. #5
    PHP manual bot bronze trophy Gaheris's Avatar
    Join Date
    Oct 2003
    Location
    Germany
    Posts
    2,195
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    There are two entries in every directory that you don't want to proccess, a single dot representing the current directory and two dots representing lower level directory.

  6. #6
    SitePoint Member
    Join Date
    Apr 2002
    Location
    Pleasant Hill, CA
    Posts
    20
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks. I think I have achieved a small level of understanding.

    Rusty


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
  •