评估PHP代码

时间:2009-08-12 19:02:54

标签: php html dreamweaver

在使用PHP时,我非常喜欢初学者。我得到了这段代码,尝试将文件夹上的文件内容输出到服务器上,但我的问题是我不知道如何阅读和修改此代码以适合我的特定文件路径。有人可以帮我解决这个问题,让我们只使用名称文件夹作为任意路径名。

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

3 个答案:

答案 0 :(得分: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);
}
?>

答案 1 :(得分:0)

<?php
$path = '.';

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

答案 2 :(得分:0)

详细说明和示例:http://www.php.net/function.opendir