views:

75

answers:

3

I am very much a beginner when it comes to using PHP. I was given this code, to try and output the contents of a files on a folder, onto a server, but my issue is I do not know how to read and alter this code to fit my specific file path. Can someone help me out with this, and lets just use the name folder as an arbitrary pathname.

<?php
if ($handle = opendir('.')) {
    while (false !== ($file = readdir($handle))) {
        if ($file != "." && $file != "..") {
            echo "$file\n";
        }
    }
    closedir($handle);
}
?>
+4  A: 
<?php

$dir_path = '.';  //      '.'      = current directory.
                  //      '..'     = parent directory.
                  //      '/foo'   = directory foo in the root file system
                  //      'folder' = a dir called 'folder' inside the current dir
                  //      'a/b'    = folder 'b' inside 'a' inside the current dir
                  //      '../a'   = folder 'a' inside the parent directory
if ($handle = opendir($dir_path)) {
  while (false !== ($file = readdir($handle))) {
    if ($file != "." && $file != "..") {
      echo "$file\n";
    }
  }
  closedir($handle);
}
?>
scragar
A: 
<?php
$path = '.';

if ($handle = opendir($path)) {
    while (false !== ($file = readdir($handle))) {
        if ($file != "." && $file != "..") {
            echo "$file\n";
        }
    }
    closedir($handle);
}
?>
phantombrain
A: 

Detailed explanation and examples: http://www.php.net/function.opendir

Mr. Smith