0

Possible Duplicate:
PHP Get all subdirectories of a given directory

Is it possible to do this, using PHP and/or Jquery/Javascript:

1) open one folder from,say, a List-menu, then

2) select the sub-folder inside it.

I do not need the contents, but just the sub-folder name only. Any help will be greatly appreciated!

Community
  • 1
  • 1
Lloyd
  • 43
  • 1
  • 8
  • @simone Thanks a lot, I just checked it out. However, mine is a bit different in that it's a manual two staged process : 1) open a main-directory. 2) select the sub-directory's name. – Lloyd Oct 09 '12 at 08:09

2 Answers2

0

Yes, it is possible. No, not via javascript (at least not when you want to get folderlistings from a machine which is not same as the client). This can be achieved by PHP. See http://www.php.net/manual/en/function.opendir.php. By using is_dir() you can check if a file in a dir is a dir.

Note, if you want to get all subfolders from a certain folder you should create a function to get the folders from a folder (as mentioned above). Then use this function recursively each time you find a folder within the folder you're searching. See for example What is a RECURSIVE Function in PHP?

Community
  • 1
  • 1
Ben Fransen
  • 10,884
  • 18
  • 76
  • 129
0

this may be helpful

if ($handle = opendir('/path/to/files')) {
    echo "Directory handle: $handle\n";
    echo "Entries:\n";

    /*  to loop over the directory. */
    while (false !== ($entry = readdir($handle))) {
        echo "$entry\n";
    }
}

also

$dir    = '/tmp';
$files1 = scandir($dir);
list all files and folders in side tmp
Arun Killu
  • 13,581
  • 5
  • 34
  • 61