Anyone have a PHP script for a file directory listing that is click-able to view sub

chuc819

New member
folders? I need a script that will load the contents of one directory (including the folders) so that the files are a link to download and also the folders can be opened and the script will change to that directory and do the same thing.

I wrote this script a long time ago but it does not allow for going backwards or into the folders.

<?php
/*
$Dir = "./testDIR/";
$DirEntries = scandir($Dir);
echo "<table border = '1' width = '60%' >\n";
echo "<tr><th colspan = '4'>Directory Listing for <strong>"
. htmlentities($Dir) . "</strong></th></tr>\n";
echo "<tr>";
echo "<th><strong><em>File Name</em></strong></th>";

echo "<th><strong><em>Size</em></strong></th>";
echo "</tr>\n";
foreach ($DirEntries as $Entry) {
if ((strcmp($Entry, '.') != 0) && (strcmp($Entry, '..') != 0)) {
$FullEntryName = $Dir . "/" . $Entry;
echo "<tr><td>";

if (is_file($FullEntryName))
echo "<a href=\"$FullEntryName\">" . htmlentities($Entry). "</a>";
echo "</td><td align = 'right'>" . number_format (filesize($FullEntryName), 0) . " bytes";
}

}
echo "</table>\n";
?>
 
Back
Top