Jump to content

scandir troubles--trying to scan multiple sub sirectories


RopeADope

Recommended Posts

Hi all.

 

I'm trying to build a dynamic multiple tiered navigation menu that operates on the existence of directories.  So far, I have some code that will read through the document root, and one sub level of directories but I'm not sure how to get into the third level of directories.  Here's what I have so far...

 

The code:

      $docroot=scandir($_SERVER['DOCUMENT_ROOT']);

      unset($docroot[array_search('.',$docroot)]);

      unset($docroot[array_search('..',$docroot)]);

      unset($docroot[array_search('php',$docroot)]);

      unset($docroot[array_search('css',$docroot)]);

      unset($docroot[array_search('input_forms',$docroot)]);

      $docroot=array_values($docroot);

      

      //Build tier 1

      echo "<div class=\"tier\">";

      echo "<a href=\"/index.php\">Home</a>";

      foreach($docroot as $value1){

         if(is_dir($value1)){

            $t2=scandir($_SERVER['DOCUMENT_ROOT'] . "/" . $value1);

            unset($t2[array_search('.',$t2)]);

            unset($t2[array_search('..',$t2)]);

            $t2=array_values($t2);

            $t1[]=$t2;

            

            echo "<a href=\"/$value1/\">";

            $value1=str_replace("_"," ",$value1);

            $value1=ucwords($value1);

            echo $value1;

            echo "</a>";

         }

      }

      echo "</div>";

 

The output:

[it automatically builds the first tier of the menu with some stylesheet definitions and places it here.  I did this just for testing purposes.]
Array
(
    [0] => Array
        (
            [0] => bus_mgmt_context.pdf
            [1] => financial_management
            [2] => index.php
            [3] => nav.php
            [4] => service_level_management
            [5] => service_portfolio
            [6] => workforce_management
        )

    [1] => Array
        (
            [0] => element_inventory
            [1] => index.php
            [2] => mobile_administration
            [3] => monthly_bill_review
            [4] => nav.php
        )

    [2] => Array
        (
            [0] => business_it_requests
            [1] => change_management
            [2] => demand_management_context.pdf
            [3] => index.php
            [4] => nav.php
            [5] => project_management
            [6] => release_management
        )

    [3] => Array
        (
            [0] => availability_management
            [1] => capacity_management
            [2] => configuration_management
            [3] => index.php
            [4] => nav.php
            [5] => planning
            [6] => problem_management
            [7] => system_planning
        )

    [4] => Array
        (
            [0] => context
            [1] => input
            [2] => reports
            [3] => sop
            [4] => t3.php
            [5] => video
        )

    [5] => Array
        (
            [0] => executive_reports
            [1] => index.php
            [2] => kpi_index
            [3] => nav.php
        )

    [6] => Array
        (
            [0] => compliance
            [1] => hipaa_definitions.pdf
            [2] => index.php
            [3] => information_security
            [4] => nav.php
            [5] => risk_context.pdf
            [6] => service_continuity
            [7] => threat_management
        )

    [7] => Array
        (
            [0] => incident_management
            [1] => index.php
            [2] => nav.php
            [3] => release_management
            [4] => service_desk
            [5] => service_requests
            [6] => supplier_management
        )

)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.