Jump to content

Dynamically determine the dir a file is in.


chronister

Recommended Posts

Hello,

 

I have a class that I am writing. This class creates some meta links (css, js files) that are placed in the header. I have a config file to define the relative path the class directory is placed in, but wish to have it figure this out dynamically.

 

My current structure is like so....

 

site root

|- class dir

  |- library dir

      |- config.php

 

I would like config.php to determine that class dir is located at /classDir/ .. and if the structure changes e.g.

 

site root

|-subDir

  |- classdir

    |- libDir

        |- config.php

 

then it determines that the class is in /subDir/classDir/

 

As I mentioned, the files are css & js files, and I would like them to be linked/referenced as /path/to/class/stuff/ so I can place the class dir anywhere, and it figures out where it lives.

 

I am pretty sure this is possible, but I can't quite get it right.

 

I used $_SERVER['PATH_TRANSLATED'], and it worked when calling the class inside a file that lives in the same dir, but when I call the class from a file in site root, it is not working.. I understand why.. but cannot quite get this one down.

 

I also tried dir_name(__FILE__) type methods, but they gave me the full server path e.g. c:\program files\....... (windows test machine)

 

Any takers on helping with this??

 

Thanks,

 

nate

 

 

 

I tried that.... It gives me the C:\Program Files\apache ..... path.... I need to dynamically determine the path to use to call js/css files.... e.g.

 

<script src="/path/to/jsFile.js" ></script>

 

or

<link href="/path/to/css/file.css" rel="stylesheet" />

 

I am not sure if it is possible to do this without some serious coding.. but I would like to find out.

 

Nate

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.