note 47958 added to function.readdir

From: Date: Tue, 07 Dec 2004 10:15:44 +0000
Subject: note 47958 added to function.readdir
Groups: php.notes 
Request: Send a blank email to php-notes+get-81478@lists.php.net to get a copy of this message
here is a simple directory navigating script i created. files and directories are links and it displays the current directory and the path relative to the file the script is in. it also has a nifty 'up one level' link. ------ <?php $path = $_GET['path']; if(!isset($path)) { $path = "."; } if ($handle = opendir($path)) { $curDir = substr($path, (strrpos(dirname($path."/."),"/")+1)); print "current directory: ".$curDir."<br>************************<br>"; print "Path: ".dirname($path."/.")."<br>************************<br>"; while (false !== ($file = readdir($handle))) { if ($file != "." && $file != "..") { $fName = $file; $file = $path.'/'.$file; if(is_file($file)) { print "[F]&nbsp;&nbsp;<a href='".$file."'>".$fName."</a>&nbsp;&nbsp;&nbsp; ".filesize($file)." bytes<br>"; } if(is_dir($file)) { print "[D]&nbsp;&nbsp;<a href='ex2.php?path=$file'>$fName</a><br>"; } } } $up = substr($path, 0, (strrpos(dirname($path."/."),"/"))); print "[^]&nbsp;&nbsp;<a href='ex2.php?path=$up'>up one level</a><br>"; closedir($handle); } ?> ------ sample output ------ current directory: kate ************************ Path: ./kate ************************ [F] xyz_file.txt 13005 bytes [F] mno_file.txt 26327 bytes [F] abc_file.txt 8640 bytes [D] k2 [^] up one level ---- Manual Page -- http://www.php.net/manual/en/function.readdir.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+47958 Delete -- http://master.php.net/manage/user-notes.php?action=delete+47958&report=yes Reason: bad code -- http://master.php.net/manage/user-notes.php?action=delete+47958&report=yes&reason=bad+code Reason: spam -- http://master.php.net/manage/user-notes.php?action=delete+47958&report=yes&reason=spam Reason: useless example -- http://master.php.net/manage/user-notes.php?action=delete+47958&report=yes&reason=useless+example Reason: contains commercial links -- http://master.php.net/manage/user-notes.php?action=delete+47958&report=yes&reason=contains+commercial+links Reason: useless note -- http://master.php.net/manage/user-notes.php?action=delete+47958&report=yes&reason=useless+note Reject -- http://master.php.net/manage/user-notes.php?action=reject+47958&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#81478) next »