TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   Absolute Beginners (http://www.talkphp.com/absolute-beginners/)
-   -   Step by step tree menu (http://www.talkphp.com/absolute-beginners/2912-step-step-tree-menu.html)

Peuplarchie 06-06-2008 02:24 AM

Step by step tree menu
 
Good day to you all,
Its been a will that I'm working on some different.
This code is used as a menu.

The following script :
- Reads recursively through a given directory.
- For each folder it count the number of files,.
- Add a "space" in front of the text for each level.

I need to make it also do :
- For each last level of each folder, change the image, in the way it display.
- Each folder collapse, expand.

I know how to :
- make table collapse and expand, see 2nd code. It need to be integrated in 1st code.
- How to make level identified by "space", see 1st code


PHP Code:


<table border="0" cellpadding="0" cellspacing="0" align="center" width="100%">

<?php

  
function CountDir($aDir$aRecurse)
  {
    
$Count 0;

    
$d dir($aDir);

    while (
$Entry $d->Read())
    {
      if (!((
$Entry == "..") || ($Entry == ".")))
      {
        if (
Is_Dir($aDir '/' $Entry))
        {
          if (
$aRecurse)
          {
            
$Count += CountDir($aDir '/' $Entry$aRecurse);
          }
        }
        else
        {
          
$Count++;
        }
      }
    }
    
    return 
$Count;
  }



function 
getDirectory$path '.'$level ){

$myFile "http://test.com/Sidebar_icon/icon_change.txt";
$fh fopen($myFile'r');
$outputt fgets($fh);
$output str_replace("../..""http://test.com/V_0-1"$outputt );
fclose($fh);


    
$ignore = array( 'cgi-bin''.''..' );
    
// Directories to ignore when listing output. Many hosts
    // will deny PHP access to the cgi-bin.

    
$dh = @opendir$path );
    
// Open the directory to the handle $dh
    
    
while( false !== ( $file readdir$dh ) ) ){
    
// Loop through the directory
    
        
if( !in_array$file$ignore ) ){
        
// Check that this file is not to be ignored
            
            
$spaces str_repeat'&nbsp;', ( $level ) );
            
// Just to add spacing to the list, to better
            // show the directory tree.
            
            
$rest substr($file0, -4);

            if( 
is_dir"$path/$file) ){
            
// Its a directory, so we need to keep reading down...

echo '<tr><td align="left"><a href="http://test.com/V_0-1/Art/images22.php?folder='.$path.'/'.$file.'" align="left" class="white00" target="image">'.$spaces.'<img src="'.$output.'" border="0"> '.$file.'</a> - '.CountDir($path.'/'.$fileFalse).' </td></tr>';





                
getDirectory"$path/$file", ($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$dh );
    
// Close the directory handle
}

getDirectory"Pictures/Pics/Pic-S" );
// Get contents of the "files/includes" folder  

?>

</table>



Code two is from Dynamic Drive script
http://http://www.dynamicdrive.com/d...chcontent2.htm


Thanks !

Peuplarchie 06-06-2008 04:19 AM

Dynamic Drive DHTML scripts- Switch Content Script


All times are GMT. The time now is 10:14 PM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0