File Directory Php

# This code will mirror a directory structure (like /home/ftp/pub, the
anonymous ftp dir) that is headed by the topdir.
# The icons it refere to are those provided by the apache server by default.
These, of course, can be switched to
# whatever you wish.
# This is probably not the most elegant way to do this and the ability to
differentiate between file types could probably
# be added, but it does work.
#




// Change this to the path to the top of the directory structure
$path = "/path/to/topdir";
// Initialize arrays
$darray[0] = "...";
$farray[0] = "...";
// Check to see if script has been called by itself
if (isset($selectdir)) {
// The selectdir variable contains subdirectories of the topdir separated by
//slashes
// Explode out these directories and list them out with "open folder icons"
if(strstr($selectdir,"/")) {
$dirarray = explode("/",$selectdir);
} else {
$dirarray[0] = $selectdir;
}
$dirsize = sizeof($dirarray);
$i = 0;
while ($i < $dirsize) {
echo "\n";
echo "\n";
echo "\n";
$i++;
}
// Append the selectdir variable on to the path we hardcoded above, resulting
// in a full path to the current directory
$path = $path."/".$selectdir;
}
// Open the directory specified in the path variable and read the resulting
// entries into two arrays
// darray = directories
// farray = all others (files)
$dir=opendir($path);
while ($file=readdir($dir)) {
if ($file!="." && $file!=".." && $file!="incoming") {
switch (filetype($path."/".$file)) {
case 'dir':
$darray[] = $file;
break;
default:
$farray[] = $file;
break;
}
}
}
closedir($dir);
// Sort the arrays by name
sort($darray);
sort($farray);
// List out the subdirectories of the current directory
$asize = sizeof($darray);
$i = 0;
while ($i < $asize) {
if ($darray[$i] != "...") {
echo "\n";
echo "\n";
echo "\n";
}
$i++;
}
// List out the files in the current directory
$asize = sizeof($farray);
$i = 0;
while ($i < $asize) {
if ($farray[$i] != "...") {
echo "\n";
echo "\n";
echo "\n";
}
$i++;
}
?>

# Change topdir to the name of the top of the directory structure you wish to
mirror
??SIZE="2">topdir
\n";
$j = -1;
while ($j < $i) {
echo "???";
$j++;
}
echo "";
echo "??";
echo "\"files.php3?selectdir=";
$j = 0;
while ($j < $i) {
echo $dirarray[$j]."/";
$j++;
}
echo $dirarray[$i];
echo "\" onMouseover=\"window.status='";
echo $dirarray[$i];
echo "'; return true\" onMouseOut=\"window.status=''; return
true\">";
echo $dirarray[$i];
echo "
\n";
echo "
\n";
$j = -1;
while ($j < $dirsize) {
echo "???";
$j++;
}
echo "";
echo "??";
echo "\"files.php3?selectdir=";
if (isset($selectdir)){
echo $selectdir."/".$darray[$i];
} else {
echo $darray[$i];
}
echo "\" onMouseover=\"window.status='";
echo $darray[$i];
echo "'; return true\" onMouseOut=\"window.status=''; return
true\">";
echo $darray[$i];
echo "
\n";
echo "
\n";
$j = -1;
while ($j < $dirsize) {
echo "???";
$j++;
}
echo "";
echo "??";
echo "\"ftp://ftp.yps.org/pub/";
if (isset($selectdir)){
echo $selectdir."/".$farray[$i];
} else {
echo $farray[$i];
}
echo "\" onMouseover=\"window.status='";
echo $farray[$i];
echo "'; return true\" onMouseOut=\"window.status=''; return
true\">";
echo $farray[$i];
echo "
\n";
echo "