home>php>newslister
News lister:
Lists files in a directory and sorts by Month.
Use this script along with the editpage script and some directory
password protection to make a very happy client...
This script requires one file:
1. Code.
<script language="php">
echo "<html>\n<head>\n<title>Directory Listing: ".dirname($PHP_SELF)."</title>\n</head>\n<body>\n<ul>\n";
$categories = array();
eregi(".*/([^/]*)$", $PHP_SELF, $namematch);
if (is_readable(getcwd())) {
$handle=opendir(getcwd());
while (($file = readdir($handle))!==false) if (!eregi("(^\.|^".$namematch[1]."$)", $file)) $categories[] = $file;
closedir($handle);
sort ($categories);
for ($i = 0; $i < sizeof($categories); $i++) {
echo "<li><a href=\"".$categories[$i]."\">".$categories[$i]."</a><br>\n";
}
}
else echo "<li><b>Error</b>: need read permission for directory!\n";
echo "</ul>\n</body>\n</html>\n";
</script>
2. Simply create a directory, throw in a batch of files, and a web page with code above and stir.
Notes:
a. Make sure your HTML file has a .php extension, not .html.
b. Make sure the directory is readable.
c. Make sure not to break up lines when copying the code. There should be 16 lines altogether.
Example: News lister