List dir, levels, and css ?
Posted: Sat Mar 08, 2008 1:02 pm
Good day to you all,
I have a piece of code which list all folder recurcivly within a specified folder and list it as a link.
Here it is :
From that code I need to make it do a real menu with in css style like the following peice of code :
I there somebody that can guide me on this, I don'tknow how to implement the part of putting each level in a different <ul></ul>.
Thanks!
Take care !
I have a piece of code which list all folder recurcivly within a specified folder and list it as a link.
Here it is :
Code: Select all
<?
// count # of image in current non-recursivly dir
function CountDirq($qDir, $qRecurse)
{
$Countq = 0;
$dq = dir($qDir);
while ($Entry = $dq->Read())
{
if (!(($Entry == "..") || ($Entry == ".")))
{
if (Is_Dir($qDir . '/' . $Entry))
{
if ($qRecurse)
{
$Countq += CountDirq($qDir . '/' . $Entry, $qRecurse);
}
}
else
{
$Countq++;
}
}
}
return $Countq;
}
function getDirectorya( $pathq = '.', $level = 0 ){
//Locate file where variable of the folder icon
$myFileq = "http://test.com/Sidebar_icon/icon_change.txt";
$fhq = fopen($myFileq, 'r');
$outputtq = fgets($fhq);
$outputq = str_replace("../..", "http://http://test.com/V_0-1", $outputtq );
fclose($fhq);
//Strat reading directory and return folder and file
$ignoreq = array( 'cgi-bin', '.', '..' );
// Directories to ignore when listing output. Many hosts
// will deny PHP access to the cgi-bin.
$dhq = @opendir( $pathq );
// Open the directory to the handle $dhq
while( false !== ( $fileq = readdir( $dhq ) ) ){
// Loop through the directory
if( !in_array( $fileq, $ignoreq ) ){
// Check that this file is not to be ignored
$spacesq = str_repeat( 'f', ( $level * 4 ) );
// Just to add spacing to the list, to better
// show the directory tree.
$restq = substr($fileq, 0, -4);
if( is_dir( "$pathq/$fileq" ) ){
// Its a directory, so we need to keep reading down...
echo '<a href="http://test.com/Art/images_public.php?folder='.$pathq.'/'.$fileq.'" class="blue0"> '.$spacesq.' <img src="'.$outputq.'" border="0" /> '.$fileq.'- '.CountDirq($pathq.'/'.$fileq, False).'</a>';
getDirectorya( "$pathq/$fileq", ($level+1) );
// Re-call this same function but on a new directory.
// this is what makes function recursive.
} else {
// Just print out the filename
}
}
}
closedir( $dhq );
// Close the directory handle
}
getDirectorya( "../Trips" );
// Get contents of the "files/includes" folder
?>
From that code I need to make it do a real menu with in css style like the following peice of code :
Code: Select all
<ul>
<li><a href="#">Link</a></li>
<li><a href="#">Link</a></li>
<li><a href="#">Link</a>
<ul>
<li><a href="#">Link</a></li>
<li><a href="#">Link</a></li>
<li><a href="#">Link</a></li>
<li><a href="#">Link</a></li>
<li><a href="#">Link</a></li>
<li><a href="#">Link</a></li>
<li><a href="#">Link</a>
<ul>
<li><a href="#">Link</a></li>
<li><a href="#">Link</a></li>
<li><a href="#">Link</a></li>
<li><a href="#">Link</a></li>
<li><a href="#">Link</a></li>
<li><a href="#">Link</a></li>
<li><a href="#">Link</a></li>
</ul>
</li>
</ul>
</li>
</ul>
I there somebody that can guide me on this, I don'tknow how to implement the part of putting each level in a different <ul></ul>.
Thanks!
Take care !