0

在使用 PHP 方面,我是一个初学者。我得到了这段代码,试图将文件夹中文件的内容输出到服务器上,但我的问题是我不知道如何读取和更改这段代码以适应我的特定文件路径。有人可以帮我解决这个问题,让我们将名称文件夹用作任意路径名。

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

3 回答 3

4
<?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);
}
?>
于 2009-08-12T19:09:45.673 回答
0
<?php
$path = '.';

if ($handle = opendir($path)) {
    while (false !== ($file = readdir($handle))) {
        if ($file != "." && $file != "..") {
            echo "$file\n";
        }
    }
    closedir($handle);
}
?>
于 2009-08-12T19:09:51.323 回答
0

详细解释和例子:http ://www.php.net/function.opendir

于 2009-08-12T19:11:07.717 回答