I think I phrased that correctly.

What I need is to call all my subnavigation includes for ALL subfolders, no matter how deep the folders go. I have it working properly for the root level of each main folder, just dont know how to set all subdirectories within.

My current code...


if ($REQUEST_URI == '/services/') {

include ("$DOCUMENT_ROOT/services/include/servicesnav.inc");
}


And I have each main nav area set up, along with my else statement which just spits out an echo.

Any help is greatly appreciated!

  • Grafix

    could you explain more? its not clear what you want.

      Um, I'm not sure how else to phrase that other than what I have stated above.

      ???

        If you're wanting to do what I think you're wanting to do you're going to have to read through the directories and include the files where you find them. I'm assuming you have a directory with many subdirectories and you have a filename and you wish to include all occurences of this filename into your script. Below is some code using a recursive algorithm (about the simplest way of getting this done) which should get the job done. I'm not quite sure how using include from within a function works though, not done it myself before.
        If you have trouble figureing out what's going on then check up on the www.php.net site for the following functions opendir, is_file, readdir, is_dir. Remember to read the comments as well as they often have some very usefull information.

        function checkAllSubdirs($dir, $file) {
            if(!$dh = opendir($dir))
                return false;
            if(is_file($dir.'/'.$file) && is_readable($dir.'/'.$file))
                include_once($dir.'/'.$file);
            while($item=readdir($dh)) {
                if(is_dir($item) && $item!='.' && $item!='..') {
                    checkAllSubdirs($dir.'/'.$item, $file);
                }
            }
            return true;
        }
        
        
        if($_SERVER['REQUEST_URI']=='/services/') {
            checkAllSubdirs($_SERVER['DOCUMENT_ROOT'].'/services', 'servicesnav.inc');
        }
        

        HTH
        Bubble

          Hey Bubble, thanks for your response. Unfortunately that function didn't seem to work, although I am looking into opendir calls and see if I can figure it out another way. I just thought I could add the * at the end of my directory listing and php would automatically include all subfolders and irectories as part of the included list. But I was wrong.

          Thx anyways -

            Write a Reply...