Results 1 to 2 of 2

Thread: Little help, readdir()

  1. #1
    Join Date
    Jan 2008
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Little help, readdir()

    PHP Code:
    <?

    $list 
    = array(); // initialize an array
    $showcaseDir opendir('../showcase/'); // attempt to open directory
    while ($f readdir($showcaseDir)) { // loop the directory
    if ($f=='.' or $f=='..' or $f=='.DS_Store') { continue; } // skip this stuff
        
    array_push($list$f); // slap it into the array
    }
    closedir($showcaseDir);

    foreach(
    $list as $l){
        echo 
    '<option value="'.$l.'">'.$l.'</option>';
    }

    ?>
    This kicks out what I want (a list of directory names in a <select> box) but it also prints the whole array afterward as just text! What part of that code is causing it to do that?

    I only want it to go into the <option> spots.

    This is my first attempt with directory fun.

    Thanks!

  2. #2
    Join Date
    Jan 2008
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Nevermind!

    I had the foreach() in the code I was referencing and then again in the context of the page, so of course it displayed twice!


    BUT, I do have this question now:

    PHP Code:
    $list = array();

    $showcaseDir opendir('../../showcase/'); 
    while (
    $f readdir($showcaseDir)) {
    if (
    $f=='.' or $f=='..' or $f=='.DS_Store') { continue; } 
        
    $t file_get_contents("absolute/address/$f/name.txt") or die('Could not read name text file!'); // looking for help here
        
    array_push($list$t);
    }


    closedir($showcaseDir);

    print_r($list); 
    I can get to push $t into the array with the absolute address. But when I try a relative path I can't get it to read the text file. I know what the path should be but it doesn't work, and neither does any other relative path I've tried (and I've tried plenty!).

    Thanks!
    Last edited by rpflorence; 02-08-2008 at 06:01 AM.

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
  •