Getting directory contents

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • endline
    New Member
    • Jun 2007
    • 10

    Getting directory contents

    Hi

    I am trying to build a small script that retrieves a list of files in a given directory, into an array, then prints them to a text file, so it can be loaded by flash into a movie clip. The idea is that someone could just upload a file to a directory and next time the page loads it would show. I found a script that does it, but I would rather have a solid understanding of how it works.

    The script I found is here
    but after searching through php.net I cannot find the getDirectoryCon tent in the function list.
  • poe
    New Member
    • Jun 2007
    • 32

    #2
    You could use the readdir() function. The following should list the contents of a directory. I'm sure there are better ways to do this, but if you want to understand how everything works then this should be fine.
    [PHP]$dirname = ".";
    $dh = opendir($dirnam e);

    while(!(($file = readdir($dh))) === false )){
    if(is_dir("$dir name/$file")){
    echo "(D) ";
    }
    echo $file . "<br />";
    }
    closedir($dh);[/PHP]
    You can do whatever you want with the contents after you've read them in, like output them to a file. This should get you started.

    Comment

    Working...