guyguy50
Cat Chaser


Joined: 28 Apr 2001 Posts: 600
Location: Ludington
|
Posted:
Fri Mar 12, 2010 5:30 am Post subject: |
|
In case anyone cared, solved this months ago with this function. May be useful to someone, actually a group of functions used for various things.
First part makes an array for ranking, then second one just simply displays using newer iteration techniques, had to use opendir for what I wanted to get the ranking and with use of a stopper file too. But it works wonderful and remarkably faster then I expected.
<?php
function Load_Tree($path, $stopper)
{
$delim = "/";
if ($dir=@opendir($path)) {
while (($element=readdir($dir))!== false)
{
if (is_dir($path.$delim.$element) && $element!= "." && $element!= ".." && $element!="Search")
{
$array[$element] = Load_Tree($path.$delim.$element, $stopper);
}
elseif ($element!= "." && $element!= "..")
{
$element = strtolower($element);
if($element == $stopper)
{
$array = array(); //DESTROY THE ARRAY IF THERE IS EVER A STRUCT FILE IN THE DIRECTORY
$array[0] = "LINK_ME";
break;
}
}
}
closedir($dir);
}
return (isset($array) ? $array : false);
}
function Nav_Link($value_array, $key_sub)
{
foreach ($value_array as $key => $value)
{
if (is_array($value) == FALSE)
{
//We do nothing Here all is taken care of in recursive section
}
if (is_array($value) == TRUE)
{
if($value[0] == "LINK_ME")
{
$temp_key = $key_sub.'/'.$key;
$temp_key = urlencode($temp_key);
echo ('<li><a href="index.php?page='.$temp_key.'">'.$key.'</a></li>');
}
else
{
echo ('<li><a href="#">'.$key.'</a>
<ul>');
Nav_Link($value, $key_sub.'/'.$key);
echo (' </ul>
</li>');
}
}
}
}
function Tree_Noder($tree_path, $orig_path)
{
$I_T_H = NULL; // I_T_H used to detect of there is anything to list. Else main program displays something like a message or the like.
$iterator = new DirectoryIterator($tree_path);
foreach ($iterator as $fileinfo)
{
if ($fileinfo->isFile() && $fileinfo!= 'struct.php' && $fileinfo!='index.php'&& $fileinfo!='index.htm'&& $fileinfo!='index.html'&& $fileinfo!='Thumbs.db')
{
$file = $fileinfo->getFilename(); //prints file
$path = $fileinfo->getPath(); // get path
//echo $file."<br>";
$file_array = explode("_",$file);
$form_num = $file_array[0];
$form_name = $file_array[1];
if($form_name != "")
{
//$file_array = explode(".",$form_name); // WAS USED TO REMOVE SUFFIX BUT NAMES HAVE "." in them too
//$form_name = $file_array[0];
echo ('<li><span class="file"><b>Name</b><strong> : </strong><a class="five" href="'.$path.'/'.$file.'" target="_blank">'.$form_name.'</a> <br><b>Form Number</b><strong> : </strong><a class="four" href="'.$path.'/'.$file.'" target="_blank">'.$form_num.'</a></span></li>');
}
else
{
//$file_array = explode(".",$file); // WAS USED TO REMOVE SUFFIX BUT NAMES HAVE "." in them too
//$form_name = $file_array[0];
echo ('<li><span class="file"><a class="four" href="'.$path.'/'.$file.'" target="_blank">'.$file.'</a></span></li>');
}
//<li><span class="file"><a href="#">Airdrie eNewsletters</a></span></li>
$I_T_H = 1;
}
//echo $orig_path;
if($fileinfo->isDir()&&$fileinfo != $orig_path)
{
if($fileinfo->isDot()) continue; //bypasses . & ..
$folder = $fileinfo->getFilename(); //prints directory//
if($folder == "Obsolete") continue; //bypasses Obsolete folders
if($folder == "THUMBS") continue; //bypasses THUMBS for now
//echo "D->".$folder."<br>";
echo('<li><span class="folder"><strong>'.$folder.'</strong></span>
<ul>');
//<li><span class="folder"><strong>Home</strong></span>
//<ul>
Tree_Noder($tree_path.'/'.$folder,$orig_path);
echo "</ul>";
$I_T_H = 1;
}
}// end of foreach
return $I_T_H;
}
?>
<?php
|
_________________
Quote:I am the Great Gibby bow before me!
Quote:Why is even the computer claiming I'm evil...
|
|