| Directories | sample contents |
// open directory and parse file list
if ($dh = opendir($dir))
{
$directories = array();
// iterate over file list
while (($val = readdir($dh)) !== false)
{
// if filename is a directory
if (is_dir($val) && ($val != "."))
{
array_push($directories, $val);
}
}
asort($directories);
while (list($key, $val) = each($directories))
{
// don't show hidden files
if(strncmp(".",$val,1) != 0 &&
strncmp("_",$val,1) != 0 &&
strncmp("src",$val,3) != 0)
{
// write html
// open row and left div
echo "\n\t";
echo "\n\t";
if($val == "..")
{
// link this section to directory
echo " ";
echo "";
echo "$val Parent Directory";
echo " | \n\t";
echo " | \n\t";
echo "
\n\t";
}
// don't show hidden files
else
{
// link this section to directory
echo "
";
echo "";
echo $val;
echo "\n\t";
echo "\n\t";
// go into the requested dir
chdir($dir . "/" . $val);
// and find files matching pattern
$infiles = glob($filePattern);
// list the first 3 file names
echo $infiles[0] . ";\n\t ";
echo $infiles[1] . ";\n\t ";
echo $infiles[2] . " ...\n\t";
echo " | \n\t";
echo "\n\t";
// return to home
chdir($dir);
}
}
// increment number of directories
$count++;
} // end while
closedir($dh);
} // end open dir
// make sure there were files
if($count == 0)
{
echo "| no directories |
";
}
// resent count
$count = 0;
echo "| Files | size | Last Modified |
";
// find files matching pattern
$files = glob($filePattern);
// sort the files
asort($files);
// iterate over files array and print filenames
foreach ($files as $filename)
{
// if filename is not a direcroty, or this file or a hidden file
if (!is_dir($filename) && $filename != "index.php" &&
strncmp(".",$filename,1)!=0)
{
$count++;
// write html
// open row and left div
echo "\n\t";
echo "\n\t";
// link this section to directory
echo " ";
echo "";
echo $filename;
echo "";
echo " | \n\t";
echo "" .
round(filesize($filename)/(int)1048576,2) .
" Mb | ";
echo "" .
date("F d Y H:i:s.", filemtime($filename)) .
" | \n\t";
echo "
\n\t";
} // end if not dir
// return to home
chdir($dir);
} // end for each
// make sure there were files
if($count == 0)
{
echo "| no files |
";
}
?>