indee
07-13-2006, 08:30 PM
since my host does not allow automatic directory listings like this http://forum.joomla.org/Themes/joomla/images/ (just googled any parent directory) i had to come up with one so i can easily download files from the directory. i found this script on planetsourcode.com and edited it a bit to make it work on my own site.
also i have a upload script which i use to upload files to the directory on my site.
i'm having trouble with getting each file in the directory to correctly read the correct filesize. i.e the file listing and links work but the filesize of each file reads the same as the last modified file in the directory.
this file is index.php in my directory
<?
////////////////////////////////////////////////////////
//Coded by: Canivour////////////////////////////////////
//Coded on: 03.19.01////////////////////////////////////
//Coded while listening to: Slipknot - Wait and Bleed///
////////////////////////////////////////////////////////
////////////////////////////////////////////////////////
//Reads a directory and displays a link to every file///
//in the directory (other directories not included)/////
//and gives some info on the file, NOTE: Info works/////
//best on Unix systems (that should be obvious ;) //////
//Happy Coding//////////////////////////////////////////
////////////////////////////////////////////////////////
//starting directory
$startDir = "/home/www/AAA/BBB/CCC";
//open directory
$openDir = opendir($startDir);
//variable that holds the number of free bytes in the directory
$freeSpace = diskfreespace($startDir);
print "<center><font face=\"Verdana, Arial, Helvetica, sans-serif\" size=\"-2\" color=\"#000000\"> ";
print "Current Directory: ".$startDir."<br>"; //Current Directory
print "Free space in directory ".$startDir.": ".$freeSpace." bytes\n"; //Free space
print "<br>";
print "<hr noshade></font></center>";
print "<table border=0 cellspacing=1 cellpadding=4>\n<tr>\n<td>\n"; //starting of table
print "<b><font size=\"+2\" face=\"Verdana, Arial, Helvetica, sans-serif\">Files</font></b>";
print "<br>";
print "<br>";
print "<table bgcolor=#000000 cellspacing=1 cellpadding=4>\n"; //another table
//loop while there are still things to be read in directory
while($path = readdir($openDir))
{
//gets the base name of file i.e instead of /home/canivour/html/index.html its index.html
$file = basename($path);
//makes sure we dont we read the . and .. direcotry (current directory and parent directory)
if($file!="." && $file!="..")
{
//if its not a directory print out the stats (can be changed for your needs)
if(!is_dir($startDir."/".$file))
{
$fullDir = $startDir."/".$file; //full directory path of file
$statCheck = stat($fullDir); //keeps info on files
print "<tr bgcolor=#ffffff><td width=500 height=20>\n";
print "<font size=\"-2\" face=\"Verdana\"><a href=".$file.">".$file."</a></font>\n"; //link to name of file
print "<font size=\"-2\" face=\"Verdana\">(".$statCheck[7]."B)</font>\n"; //link to name of file
print "</td></tr>\n";
} //end if
} //end if
} //end while
?>
at the moment it looks like this when viewd in the browser:
<html>
<head>
<title>Index of XXX</title>
<style>
<!--
a:link { text-decoration: none; color:#000000}
a:visited { color: #FF0000; text-decoration: line-through}
a:active { color: #000000; text-decoration: none}
a:hover { color: #000000; text-decoration: underline}
-->
</style>
</head>
<center><font face="Verdana, Arial, Helvetica, sans-serif" size="-2" color="#000000"> Current Directory: /home/www/AAA/BBB/CCC<br>Free space in directory /home/www/AAA/BBB/CCC: 705623380 bytes
<br><hr noshade></font></center><table border=0 cellspacing=1 cellpadding=4>
<tr>
<td>
<b><font size="+2" face="Verdana, Arial, Helvetica, sans-serif">Files</font></b><br><br><table bgcolor=#000000 cellspacing=1 cellpadding=4>
<tr bgcolor=#ffffff><td width=500 height=20>
<font size="-2" face="Verdana"><a href=index.php>index.php</a></font>
<font size="-2" face="Verdana">(4096B)
</td></tr>
<tr bgcolor=#ffffff><td width=500 height=20>
<font size="-2" face="Verdana"><a href=test.txt>test.txt</a></font>
<font size="-2" face="Verdana">(4096B)
</td></tr>
<tr bgcolor=#ffffff><td width=500 height=20>
<font size="-2" face="Verdana"><a href=test02.txt>test02.txt</a></font>
<font size="-2" face="Verdana">(4096B)
</td></tr>
</html>
any help would be much appreciated
also i have a upload script which i use to upload files to the directory on my site.
i'm having trouble with getting each file in the directory to correctly read the correct filesize. i.e the file listing and links work but the filesize of each file reads the same as the last modified file in the directory.
this file is index.php in my directory
<?
////////////////////////////////////////////////////////
//Coded by: Canivour////////////////////////////////////
//Coded on: 03.19.01////////////////////////////////////
//Coded while listening to: Slipknot - Wait and Bleed///
////////////////////////////////////////////////////////
////////////////////////////////////////////////////////
//Reads a directory and displays a link to every file///
//in the directory (other directories not included)/////
//and gives some info on the file, NOTE: Info works/////
//best on Unix systems (that should be obvious ;) //////
//Happy Coding//////////////////////////////////////////
////////////////////////////////////////////////////////
//starting directory
$startDir = "/home/www/AAA/BBB/CCC";
//open directory
$openDir = opendir($startDir);
//variable that holds the number of free bytes in the directory
$freeSpace = diskfreespace($startDir);
print "<center><font face=\"Verdana, Arial, Helvetica, sans-serif\" size=\"-2\" color=\"#000000\"> ";
print "Current Directory: ".$startDir."<br>"; //Current Directory
print "Free space in directory ".$startDir.": ".$freeSpace." bytes\n"; //Free space
print "<br>";
print "<hr noshade></font></center>";
print "<table border=0 cellspacing=1 cellpadding=4>\n<tr>\n<td>\n"; //starting of table
print "<b><font size=\"+2\" face=\"Verdana, Arial, Helvetica, sans-serif\">Files</font></b>";
print "<br>";
print "<br>";
print "<table bgcolor=#000000 cellspacing=1 cellpadding=4>\n"; //another table
//loop while there are still things to be read in directory
while($path = readdir($openDir))
{
//gets the base name of file i.e instead of /home/canivour/html/index.html its index.html
$file = basename($path);
//makes sure we dont we read the . and .. direcotry (current directory and parent directory)
if($file!="." && $file!="..")
{
//if its not a directory print out the stats (can be changed for your needs)
if(!is_dir($startDir."/".$file))
{
$fullDir = $startDir."/".$file; //full directory path of file
$statCheck = stat($fullDir); //keeps info on files
print "<tr bgcolor=#ffffff><td width=500 height=20>\n";
print "<font size=\"-2\" face=\"Verdana\"><a href=".$file.">".$file."</a></font>\n"; //link to name of file
print "<font size=\"-2\" face=\"Verdana\">(".$statCheck[7]."B)</font>\n"; //link to name of file
print "</td></tr>\n";
} //end if
} //end if
} //end while
?>
at the moment it looks like this when viewd in the browser:
<html>
<head>
<title>Index of XXX</title>
<style>
<!--
a:link { text-decoration: none; color:#000000}
a:visited { color: #FF0000; text-decoration: line-through}
a:active { color: #000000; text-decoration: none}
a:hover { color: #000000; text-decoration: underline}
-->
</style>
</head>
<center><font face="Verdana, Arial, Helvetica, sans-serif" size="-2" color="#000000"> Current Directory: /home/www/AAA/BBB/CCC<br>Free space in directory /home/www/AAA/BBB/CCC: 705623380 bytes
<br><hr noshade></font></center><table border=0 cellspacing=1 cellpadding=4>
<tr>
<td>
<b><font size="+2" face="Verdana, Arial, Helvetica, sans-serif">Files</font></b><br><br><table bgcolor=#000000 cellspacing=1 cellpadding=4>
<tr bgcolor=#ffffff><td width=500 height=20>
<font size="-2" face="Verdana"><a href=index.php>index.php</a></font>
<font size="-2" face="Verdana">(4096B)
</td></tr>
<tr bgcolor=#ffffff><td width=500 height=20>
<font size="-2" face="Verdana"><a href=test.txt>test.txt</a></font>
<font size="-2" face="Verdana">(4096B)
</td></tr>
<tr bgcolor=#ffffff><td width=500 height=20>
<font size="-2" face="Verdana"><a href=test02.txt>test02.txt</a></font>
<font size="-2" face="Verdana">(4096B)
</td></tr>
</html>
any help would be much appreciated