Jump to content

How to detect parent directory dynamically?


harbingerkun

Recommended Posts

Can anyone help me with this? I am trying to dynamically detect the path for
includes located outside the document root. The includes are stored in a folder
called 'libs' one level above the document root as a means of security. Because
of the nature of the application, using an absolute path such as '/var/www/libs/'
is not an option. This path must be set dynamically. What is the best method to
achieve this?


Directory Structure:

[tt]    /var/
        /lib/
            include.php
        /www/
            index.php[/tt]
           
           
If it's always the directory above the document root, and your document root is configured correctly, you should be able to do something similar to this...

[code]
<?php
$includeDir = $_SERVER['DOCUMENT_ROOT']."/../";
?>
[/code]

...which would find your document root, as configured by server, and go one level up.  This would be the same in any file.

HTH

Dest

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.