In
Simon Begin said:
I'm searching for a tool that automates creation of simple index.htm
files based on what's on the current directory. I will schedule it
every night.
Can anyone suggest me some utility or tool?
Are you able to run PHP? If so, it can dynamically create a page each time
it is visited, with no need for scheduling, and you can customise how it
looks. Or, you should be able to also use .htaccess "Options Indexes" should
do it.
http://httpd.apache.org/docs-2.0/mod/core.html#options
Here's a PHP example... It does not display files starting with ".". It
allows header files. It lets you change the timezone if you want to display
in a local time that is different from the server time. Sorts by file name.
Provides hyperlinks to the files. Call it index.php.
----------------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>The files</title>
</head>
<body>
<?php
$header_img = ".header.jpg";
$footer_img = ".footer.jpg";
if (file_exists($header_img)) echo "<img src=\"$header_img\" alt=\"\">\n";
echo "<h3>The files</h3>";
// Returns a nicely formatted filesize from a number of bytes.
function getfilesize($bytes) {
if ($bytes >= 1099511627776) {
$return = round($bytes / 1024 / 1024 / 1024 / 1024, 2);
$suffix = "TB";
} elseif ($bytes >= 1073741824) {
$return = round($bytes / 1024 / 1024 / 1024, 2);
$suffix = "GB";
} elseif ($bytes >= 1048576) {
$return = round($bytes / 1024 / 1024, 2);
$suffix = "MB";
} elseif ($bytes >= 1024) {
$return = round($bytes / 1024, 2);
$suffix = "KB";
} else {
$return = $bytes;
$suffix = "Bytes";
}
$return .= " " . $suffix;
return $return;
}
$self = basename($_SERVER['PHP_SELF']);
$selfdir = dirname($_SERVER['PHP_SELF']);
$upload_folder = $_SERVER['DOCUMENT_ROOT'] . $selfdir;
$i = 0;
$timezonediff=16;
echo "Your city time now should be: ";
echo date("Y-m-d g:i A", mktime(date("H")+$timezonediff, date("i"),
date("s"), date("m") ,date("d"), date("Y")));
echo "<br><br>\n";
$handle = opendir($upload_folder);
while (false !== ($file = readdir($handle))) {
// echo "File: $file<br>\n";
if (($file == ".." && $selfdir != "/") || (substr($file, 0, 1) != "."
&& $file != $self)) {
$filearray[$i] = $file;
$i++;
} // if
} // while
closedir($handle);
sort($filearray);
reset($filearray);
echo "<table>\n";
echo "<tr><td><b>File
name</b></td><td><b>Uploaded</b></td><td><b>Size</b></td></tr>\n";
while (list($key, $val) = each($filearray))
{
$outstr = "<tr><td><a href=\"$val\">$val</a></td><td>";
$outstr .= (is_dir($val)?("[directory]")
date("Y-m-d g:i A",
mktime(date("H", filemtime($val))+$timezonediff, date("i", filemtime($val)),
date("s", filemtime($val)), date("m", filemtime($val)), date("d",
filemtime($val)), date("Y", filemtime($val))))));
$outstr .= "</td><td>";
$outstr .= (is_dir($val)?(" ")
getfilesize(filesize($val))));
$outstr .= "</td></tr>\n";
echo $outstr;
}
echo "</table>\n";
?>
<?php
if (file_exists($footer_img)) echo "<br><img src=\"$footer_img\"
alt=\"\">\n";
?>
</body>
</html>