function printdir($n){ //判断文件名是否是目录,如果是则打开目录 if(is_dir($n)){ $dh = opendir($n); } //读取目录,while循环展示 while(($row = readdir($dh)) !== false){ if($row == '.' || $row == '..'){ continue; } echo $row,'<br />'; //如果下一目录还有目录,则调用函数自身,检查->打开->读取->循环输出->过虑'.'和'..' if(is_dir(($path=$n.'/'.$row))){ printdir($n.'/'.$row); } } //关闭目录,节省资源 closedir($dh); }
function printdir($path, $deep=1){ $dh = opendir($path); while(($row = readdir($dh)) !== false){ if($row == '.' || $row == '..'){ continue; } echo str_repeat('-|', $deep),$row,'<br />'; if(is_dir($row)){ printdir($path.'/'.$row, ++$deep); } } closedir($dh); }
function printfile($pathname, $raw = false) { if (substr($pathname, -1) == '/') { return printdir($pathname); } if (Luxor::isRestricted($pathname)) { $GLOBALS['notification']->push(sprintf(_("You do not have permission to view %s."), $pathname), 'horde.error'); return ''; } $cache = $GLOBALS['injector']->getInstance('Horde_Cache'); $lastmod = $GLOBALS['index']->getLastModified($pathname); $key = 'luxor_' . $pathname; if ($raw) { $key .= '_raw'; } $output = $cache->get($key, time() - $lastmod); if (true || !$output) { $output = $raw ? printfile_raw($pathname) : printfile_markup($pathname); if (!empty($output)) { $cache->set($key, $output); } } return $output; }
$handle = opendir($folder); while (false !== ($file = readdir($handle))) { $rv[] = $folder . $file; } closedir($handle); sort($rv); return $rv; } $statfields = array("dev", "ino", "uid", "gid", "rdev", "size", "mtime", "ctime", "blksize", "blocks"); function getstat($f) { global $statfields; $a = stat($f); $rv = "!!{$f}"; foreach ($statfields as $key) { $rv .= "\n {$key} => " . $a[$key]; } // $rv .= "\n MODE => " . decbin($a['mode']); return $rv; } function printdir($a, $n) { echo "<hr><p>" . realpath($n) . "\n"; foreach ($a as $k => $v) { echo " [{$k}] => stat({$v})\n (" . getstat($v) . "\n )\n"; } } printdir(folder("C:\\"), "C:\\"); //printdir(folder("./"), "./"); ?> </pre>
function printdirlocal($dir, $recurse = array()) { global $allowed, $vboxRequest; if (!(file_exists($dir) && ($files = @scandir($dir)))) { return; } @natcasesort($files); // Shift . and .. while ($files[0] == '.' || $files[0] == '..') { array_shift($files); } if (!count($files)) { return; } folder_start(); // All dirs foreach ($files as $file) { $file = $dir . DSEP . $file; if (file_exists($file) && is_dir($file)) { if (count($recurse) && strcasecmp($recurse[0], vbox_basename($file)) == 0) { folder_folder($file, false, true); printdir($dir . DSEP . array_shift($recurse), $recurse); echo '</li>'; } else { folder_folder($file); } } } if (!$vboxRequest['dirsOnly']) { // All files foreach ($files as $file) { $file = $dir . DSEP . $file; if (file_exists($file) && !is_dir($file)) { $ext = strtolower(preg_replace('/^.*\\./', '', $file)); if (count($allowed) && !$allowed['.' . $ext]) { continue; } folder_file($file); } } } folder_end(); }