note 47958 deleted from function.readdir by tularis
| From: | tularis@php.net | Date: | Sun, 13 May 2007 19:04:05 +0000 |
| Subject: | note 47958 deleted from function.readdir by tularis | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-126534@lists.php.net to get a copy of this message | ||
Note Submitter: BY626
----
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] <a
href='".$file."'>".$fName."</a>
".filesize($file)." bytes<br>";
}
if(is_dir($file))
{
print "[D] <a
href='ex2.php?path=$file'>$fName</a><br>";
}
}
}
$up = substr($path, 0, (strrpos(dirname($path."/."),"/")));
print "[^] <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