musher
02-16-2006, 10:13 PM
I'm having some problems understanding and change some code I have to maintain that creates a list of files in a folder.
This was orgininaly set up for a single folder with no sub folders I've added sub folders but do not want them listed in the displayed table of files, just a list of files (or thumbnails as is the case).
below are the two functions that build the table (file/directory) list, part of what's got me confused is the preg_match line in the GetDirList function I think thats stripping out . and .. but not sure (I've read and read docs but it isn't sinkin in)
if some one could explain that to me and also point me in the right direction of striping out the folder names I'd be most gratefull.
function BuildImageTable($Directory) {
$p_Files = GetDirList($Directory);
$sTableFormat = "<table border=\"3\" cellspacing=\"0\" cellpadding=\"20\">{ROWS}</table>";
$sRows = "";
$NumCols = 3;
for($iRow = 0; $iRow <= count($p_Files) / $NumCols; $iRow++) {
$sRows .= "<tr>";
for($iCol = 0; $iCol < $NumCols; $iCol++) {
$iElem = $iRow * $NumCols + $iCol;
if($iElem >= count($p_Files)) {
break;
}else{
$sRows .= "<td valign=bottom><center><a CLASS=\"h3\" HREF=\"$Directory/{$p_Files[$iElem]}\" TARGET=\"_blank\"><IMG SRC=\"$Directory/Thumbnails/{$p_Files[$iElem]}\" BORDER=\"0\"></a></center>
<center>{$p_Files[$iElem]}</center><center><a CLASS=\"h3\" HREF=\"Upload.php?value={$p_Files[$iElem]}&dir=$Directory\" TARGET=\"_top\"> Delete</a></center>";
}
}
$sRows .= "</tr>";
}
return str_replace("{ROWS}", $sRows, $sTableFormat);
}
function GetDirList($dir) {
$dl = array();
if ($hd = opendir($dir)) {
while ($sz = readdir($hd)) {
if (preg_match("/^\./",$sz)==0) {
$dl[] = $sz;
}
}
closedir($hd);
}
asort($dl);
return $dl;
}
This was orgininaly set up for a single folder with no sub folders I've added sub folders but do not want them listed in the displayed table of files, just a list of files (or thumbnails as is the case).
below are the two functions that build the table (file/directory) list, part of what's got me confused is the preg_match line in the GetDirList function I think thats stripping out . and .. but not sure (I've read and read docs but it isn't sinkin in)
if some one could explain that to me and also point me in the right direction of striping out the folder names I'd be most gratefull.
function BuildImageTable($Directory) {
$p_Files = GetDirList($Directory);
$sTableFormat = "<table border=\"3\" cellspacing=\"0\" cellpadding=\"20\">{ROWS}</table>";
$sRows = "";
$NumCols = 3;
for($iRow = 0; $iRow <= count($p_Files) / $NumCols; $iRow++) {
$sRows .= "<tr>";
for($iCol = 0; $iCol < $NumCols; $iCol++) {
$iElem = $iRow * $NumCols + $iCol;
if($iElem >= count($p_Files)) {
break;
}else{
$sRows .= "<td valign=bottom><center><a CLASS=\"h3\" HREF=\"$Directory/{$p_Files[$iElem]}\" TARGET=\"_blank\"><IMG SRC=\"$Directory/Thumbnails/{$p_Files[$iElem]}\" BORDER=\"0\"></a></center>
<center>{$p_Files[$iElem]}</center><center><a CLASS=\"h3\" HREF=\"Upload.php?value={$p_Files[$iElem]}&dir=$Directory\" TARGET=\"_top\"> Delete</a></center>";
}
}
$sRows .= "</tr>";
}
return str_replace("{ROWS}", $sRows, $sTableFormat);
}
function GetDirList($dir) {
$dl = array();
if ($hd = opendir($dir)) {
while ($sz = readdir($hd)) {
if (preg_match("/^\./",$sz)==0) {
$dl[] = $sz;
}
}
closedir($hd);
}
asort($dl);
return $dl;
}