...

View Full Version : List dir, levels, and css ?



Peuplarchie
03-08-2008, 07:01 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 :




<?

// 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 :




<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 !

Peuplarchie
03-10-2008, 12:27 AM
Now I have this code but it only read one directory and return errors :




<?


function dirlist($dir)
{


$dh = opendir($dir);

// the trick is creating the appropriate list tags
// before and after the loop
echo "<ul>";
while(($file = readdir($dh)) !== false)
{
if($file == "." || $file == "..")
continue;
echo "<li>";
if(is_file($file))
{

echo "<a href=\"http://test.com/Art/images_public.php?folder='.$file.'\" class=\"blue0\">$file</a>";
} else {
echo $file;
dirlist($file);
echo "</li>";
}
}
echo "</ul>";

}

dirlist ("../../Art/Pictures/Pics/Pic-S");
?>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum