note 46126 added to function.opendir

From: Date: Thu, 30 Sep 2004 04:08:17 +0000
Subject: note 46126 added to function.opendir
Groups: php.notes 
Request: Send a blank email to php-notes+get-77603@lists.php.net to get a copy of this message
<?php /* ** This recursive file lister only slurps in one page at time, ** so it doesn't take forever to load when operating over ** a large system.....comes with an "Up" link for every page too. */ $PHP_SELF = $_SERVER['PHP_SELF']; $DOCUMENT_ROOT = $_SERVER['DOCUMENT_ROOT']; # activate the next line (and deactivate the last) to # use this script in a $DOCUMENT_ROOT/~anybody # environment. #$DOCUMENT_ROOT="/home/sandy/public_html/"; $tdir = $_GET['dir']; echo "tdir==$tdir<br>"; $tparent_path = $_GET['parent_path']; $dbg = $_GET['dbg']; if(!strstr($tdir, $DOCUMENT_ROOT)) $tdir = getcwd(); if(!strstr($tparent_path, $DOCUMENT_ROOT)) $tparent_path = $tdir; if (!isset ($tdir)) { $dir = getcwd (); } else $dir = $tdir; if (!isset ($tparent_path)) { $parent_path = $dir; } else $parent_path = $tparent_path; echo "<br>"; if (!isset ($tdir)) { $upurl = $PHP_SELF; } else { if ($parent_path == $DOCUMENT_ROOT) $parent_parent_path = $parent_path; else $parent_parent_path = dirname ($parent_path); $upurl = $PHP_SELF."?dir=".$parent_path."&parent_path=". $parent_parent_path; } if($dbg==1) { echo "PHP_SELF: $PHP_SELF<br>\n"; echo "DOCUMENT_ROOT: $DOCUMENT_ROOT<br>\n"; echo "dir: $dir<br>\n"; echo "parent_path: $parent_path<br>\n"; echo "upurl: $upurl<br>\n"; } echo "<a href=\"$upurl\"> <h3>Up</h3> </a>\n"; echo "<h2>$dir</h2>\n"; create_tree ($dir, $parent_path); function urlFromPath ($path) { global $PHP_SELF; global $DOCUMENT_ROOT; $prefix = ""; if (substr ($path, 0, 1) != "/") $prefix = "/"; $url = $prefix.ereg_replace ($DOCUMENT_ROOT, "", $path); return $url; } function create_tree ($dir, $parent_path) { if ($handle = opendir ($dir)) { $i = 0; while (false !== ($file = @readdir ($handle))) { if ($file != "." && $file != "..") { $list[$i] = $file; $i++; } } $dir_length = count ($list); echo "<ul>"; for ($i = 0; $i < $dir_length; $i++) { global $PHP_SELF; global $DOCUMENT_ROOT; $label = $list[$i]; $test = $dir."/".$label; $alink = $dir."/".ereg_replace(" ","%20",$label); if (!strstr ($PHP_SELF, $label)) { if (is_dir ($test)) { $tmp = $PHP_SELF. "?dir=".$alink."&parent_path=".$dir; $url = ereg_replace(" ", "%20", $tmp); echo "$url<br>\n"; echo "<a href=\"$url\"><b>$label</b>/</a><br>\n"; } else { $link = urlFromPath ($alink); $label = $list[$i]; echo "<a href=\"$link\">".$label."</a><br>\n"; } } } echo "</ul>"; closedir ($handle); } } ?> ---- Manual Page -- http://www.php.net/manual/en/function.opendir.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+46126 Delete -- http://master.php.net/manage/user-notes.php?action=delete+46126&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+46126&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#77603) next »