[thelist] PHP was CF: Determining Account Root?

David Altherr einstein314 at hotmail.com
Sat Aug 18 18:05:26 CDT 2001


    This may not apply, considering I have no idea what CF code even looks
like, but I do use a similar model in my PHP scripts in which I have
navigation functions and include files which are dependent on the current
scripts relative location within the filesystem.  If not applicable to CF
then this may still offer two solutions to this common problem for the PHP
readers.

My model would look i bit like:

d:\project_name
    \includes
        \nav_functions.php
    \content
        \category
            \subcategory
                \content_page.php

where my content_page.php calls functions in the included nav_functions.php:
thus, any page must know the relative path to include the nav_functions.php
file and functions within said file must generate navigation links relative
to the original page that called nav_functions.php... confusing.

but getting back to your model, shown at the bottom of the page, I'm
assuming that, in any given script, you want to translate:

    d:\inetpub\wwwroot\MyClient\Application\Admin\dsp_Nav.cfm

into a path relative to includingframe.cfm:

    ..\..\MyClient\Application\Admin\dsp_Nav.cfm

In PHP, and I sure this can be easily translated into any language, one
solution is to assign a relative $root_path variable on each of your scripts
that might use the navigation code as such:

    $root_path = '..\..\';

and then in your dsp_Nav.cfm script (which I assume generates navigation
links of some sort), you would prepend the $root_path variable to relative
path of any other files as seen from the 'd:\inetpub\wwwroot' directory:

    $nav_link = $root_path.'MyClient\some_other_folder\content.cfm';

and would thus be the equivalent of (as seen from includingframe.cfm):

    $nav_link = '..\..\MyClient\some_other_folder\content.cfm';

and thus:

    $nav_link = 'd:\inetpub\wwwroot\MyClient\some_other_folder\content.cfm';

One other solution (this may be a little more native to PHP/Perl), is to use
pattern amtching string replacement functions on the current path, this
might address your question a little more directly.

Assuming that the 'MyClient' folder name doesn't change or can be assigned
in the script, you can use the following to determine the absolute path
below the folder:

    $client_name = "MyClient";
    $abs_root =
        preg_replace(
            "/($client_name\\.*)/",
            '',
            $current_template_path);

that will take

    d:\inetpub\blahblah\MyClient\Admin\includingframe.cfm

and give you

    d:\inetpub\blahblah\

and then you can do whatever you want with that or, more inportantly, you
can determine the relative path from any file to the root path; you would
then have to:

    /* subtract root from template name */
    $root_path =
        preg_replace(
            "/($abs_root)/",
            '',
            $current_template_path);

    /* replace all the directory names with '..'
        i might be wrong on the regexp behavior here :) */
    $root_path =
        preg_replace(
            "/([.^\\]*)/",
            '..',
            $root_path);

    /* and delete the generated trailing '..\..'
        which was 'cur_folder\cur_file' */
    $root_path =
        preg_replace(
            "/(\.\.\\\.\.)/",
            '',
            $root_path);

all that should convert:

    d:\inetpub\blahblah\MyClient\Admin\includingframe.cfm

into:

    ..\..\

which is the relative path from

    d:\inetpub\blahblah\MyClient\Admin\includingframe.cfm

to

    d:\inetpub\blahblah\

Again, I haven't the slightest as to how the above code would translate to
CF, especially the second solution, but the first should be easy in any
language.

-David Altherr
www.davidaltherr.net


> Can anyone suggest how I could determine the root folder of an account?
>
> I've got it set up so that I include the navigation for an
> application in a frame kept in a folder external to the application
> folder.
>
> Here's my nav scheme
>
> d:\inetpub\wwwroot
>      \MyClient
>          \Admin
>              \includingframe.cfm
>          \Application
>              \Admin
>                  \dsp_Nav.cfm
>
> What I want to do is to create a relative path where I can subtract
> d:\inetpub\wwwroot from GetCurrentTemplatePath(). So how can I
> calculate what d:\inetpub\wwwroot would be?
>
> Thanks

> Frank Marion                      Loofah Communications
> frank at loofahcom.com               http://www.loofahcom.com





More information about the thelist mailing list