http://metalhead.ws/phpbin/sitemap.php
scriptet viser filer (navn,størrelse..) i en mappe på webserveren.
problemmet er bare at scriptet kun viser html filer og det kun viser filer i
det dir, som selve scriptet ligger i.
hvordan ændrer jeg scriptet til at det er en bestemt mappe
(
www.ingenting.dk/files/) og at den viser alle filer?
tak for hjælpen
script:
<?php
$stime = gettimeofday();
/* some preliminaries... */
$root = getcwd();
$pre = explode("/", $_SERVER['REQUEST_URI']);
array_pop($pre);
$prefix = join("/", $pre);
/* Uncomment the 2 lines below to create a tree of all files and directories
on your webserver if the script
* is in a subdirectory */
//$root = str_replace($prefix, "", $root);
//$prefix = "";
$root .= "/";
/* Display server name and directory */
echo "<table cellspacing=0 cellpadding=0 border=0>\n";
echo "<tr><td><img align=absmiddle src=server.gif>
http://".$_SERVER['SERVER_NAME'];
echo "$prefix/";
echo "</td></tr><tr><td><img align=absmiddle src=vertical.gif></td></tr>\n";
function get_extension($name) {
$array = explode(".", $name);
$retval = strtolower(array_pop($array));
return $retval;
}
/* Recursion, here we go.. */
function list_dir($chdir) {
/* some globals, some cleaning */
global $root, $prefix, $showsize, $display, $excludedir, $excludefile;
unset($sdirs);
unset($sfiles);
chdir($chdir);
$self = basename($_SERVER['PHP_SELF']);
/* open current directory */
$handle = opendir('.');
/* read directory. If the item is a directory, place it in $sdirs, if it's
a filetype we want
* and not this file, put it in $sfiles */
while ($file = readdir($handle))
{
if(is_dir($file) && $file != "." && $file != ".." && !in_array($file,
$excludedir))
{ $sdirs[] = $file; }
elseif(is_file($file) && $file != "$self" &&
array_key_exists(get_extension($file), $display)
&& !in_array($file, $excludefile))
{ $sfiles[] = $file; }
}
/* count the slashes to determine how deep we're in the directory tree and
how many
* nice bars we need to add */
$dir = getcwd();
$dir1 = str_replace($root, "", $dir."/");
$count = substr_count($dir1, "/") + substr_count($dir1, "\\");
/* display directory names and recursively list all of them */
if(is_array($sdirs)) {
sort($sdirs);
reset($sdirs);
for($y=0; $y<sizeof($sdirs); $y++) {
echo "<tr><td>";
for($z=1; $z<=$count; $z++)
{ echo "<img align=absmiddle src=vertical.gif> "; }
if(is_array($sfiles))
{ echo "<img align=absmiddle src=verhor.gif>"; }
else
{ echo "<img align=absmiddle src=verhor1.gif>"; }
echo "<img align=absmiddle src=folder.gif> <a
href=\"
$sdirs[$y]";'>http://".$_SERVER['SERVER_NAME']."$prefix/$dir1$sdirs[$y]\">$sdirs[$y]";
list_dir($dir."/".$sdirs[$y]);
}
}
chdir($chdir);
/* iterate through the array of files and display them */
if(is_array($sfiles)) {
sort($sfiles);
reset($sfiles);
$sizeof = sizeof($sfiles);
/* what file types shall be displayed? */
for($y=0; $y<$sizeof; $y++) {
echo "<tr><td>";
for($z=1; $z<=$count; $z++)
{ echo "<img align=absmiddle src=vertical.gif> "; }
if($y == ($sizeof -1))
{ echo "<img align=absmiddle src=verhor1.gif>"; }
else
{ echo "<img align=absmiddle src=verhor.gif>"; }
echo "<img align=absmiddle src=\"";
echo $display[get_extension($sfiles[$y])];
echo "\"> ";
echo "<a
href=\"
$sfiles[$y]";'>http://".$_SERVER['SERVER_NAME']."$prefix/$dir1$sfiles[$y]\">$sfiles[$y]";
if($showsize) {
$fsize = @filesize($sfiles[$y])/1024;
printf(" (%.2f kB)", $fsize);
}
echo "</td></tr>";
echo "<tr><td>";
}
echo "<tr><td>";
for($z=1; $z<=$count; $z++)
{ echo "<img align=absmiddle src=vertical.gif> "; }
echo "</td></tr>\n";
}
}
list_dir($root);
echo "</table>\n";
?>