Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Feb 2006
    Posts
    262
    Thanks
    23
    Thanked 1 Time in 1 Post

    Post List dir, levels, and css ?

    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 :

    PHP Code:

    <?

    // 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 ){

    //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 ) );
                
    // Just to add spacing to the list, to better
                // show the directory tree.
                
                
    $restq substr($fileq0, -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.'/'.$fileqFalse).'</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:
    	<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 !

  • #2
    Regular Coder
    Join Date
    Feb 2006
    Posts
    262
    Thanks
    23
    Thanked 1 Time in 1 Post
    Now I have this code but it only read one directory and return errors :

    PHP Code:

    <?


    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");
    ?>


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •