Simple File List in PHP
Posted by on Tue, 1 Apr 2008
Here is a very simple file list written in php, stick it in any directory and it will list that directory's files. If you would like to list a different directory then the one the script is in, you can change the $dirpath variable accordingly. If you use this script, post a comment saying whats up.
<html>
<head>
<title><?php echo getcwd(); ?></title>
</head>
<body>
<h1><?php echo getcwd(); ?></h1>
<ul>
<?php
$dirpath = ".";
$dh = opendir($dirpath);
while (false !== ($file = readdir($dh))) {
if($file == "..") {
echo "<li><a href=\"$file\">Parent Directory</a></li>";
} else if($file != ".") {
echo "<li><a href=\"$file\">$file</a></li>";
}
}
closedir($dh);
?>
</ul>
</body>
</html>