Page 1 of 1

Build a select list from folder contents

Posted: Mon Dec 03, 2007 3:18 pm
by Johnlbuk
Hi Guys, I was wondering if you could help me.
I am trying to built a module based system. So far I have a modules folder which I would like to place php files. In the admin sections I would like to create a select list from the files contents which I can then select and activate the module. I would like to do it this way so that each time I add a module I do not have to add to the list it will automatically be added to the list which I can then activate.

Any help or code examples would be great.
Thank you,
John

Posted: Mon Dec 03, 2007 3:41 pm
by Johnlbuk
This is the function I have so far but it is not working.

Code: Select all

function getFileList($dir)
  {
    # array to hold return value
    $retval = array();

    # add trailing slash if missing
    if(substr($dir, -1) != "/") $dir .= "/";

    # open pointer to directory and read list of files
    $d = @dir($dir) or die("getFileList: Failed opening directory $dir for reading");
    while(false !== ($entry = $d->read())) {
      # skip hidden files
      if($entry[0] == ".") continue;
      if(is_dir("$dir$entry")) {
        $retval[] = array(
          "name" => "$dir$entry/",
          "type" => filetype("$dir$entry"),
          "size" => 0,
          "lastmod" => filemtime("$dir$entry")
        );
      } elseif(is_readable("$dir$entry")) {
        $retval[] = array(
          "name" => "$dir$entry",
          "type" => mime_content_type("$dir$entry"),
          "size" => filesize("$dir$entry"),
          "lastmod" => filemtime("$dir$entry")
        );
      }
    }
    $d->close();

    return $retval;
  }

did you check dir on php.net

Posted: Tue Dec 04, 2007 6:27 pm
by yacahuma
did you check dir on php.net . There seems to be a bunch of examples to do just that