Re[2]: Document root, preferred way to find it???

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Leif,

Monday, March 7, 2005, 10:03:48 AM, you wrote:
LG> Hello Tom,

LG> Friday, March 4, 2005, 9:13:41 PM, you wrote:
TR>> This will set the include path just before the document root:

LG> Hmmmm. Not quite what I'm looking for. I set up some test folders and
LG> files on a development machine to play with your script.

LG> Here's how it was laid out:

LG> The document root for the test site:
LG> "c:\sambar\docs\test"

LG> A subfolder of the doc root
LG> "folder1"

LG> A subfolder of the above folder1
LG> "folder2"

LG> Placing a file called test.php (containing your script) in all three
LG> places (doc root, folder1, folder1/folder2) gives you the following
LG> respectively. 

LG> Root: c:\sambar\docs\test\test.php
LG> Document root: c:\sambar\docs\test\test.php     <<<this is wrong
LG> Base: test.php
LG> Include: c:\cambar\docs\test\include
LG> OS: winnt
LG> Include: c:\cambar\docs\test\include;.;C:\php5\pear

Try running this one:

<?php
if(isset($_SERVER["SCRIPT_FILENAME"])){
        $file_name = $_SERVER['SCRIPT_FILENAME'];
        echo "File name: $file_name<br>";
        
        $script = $_SERVER['SCRIPT_NAME'];
        echo "Script: $script<br>";
        
        $document_root = str_replace($script,'',$file_name);
        echo "Document root: $document_root<br>";
        
        $base = basename($document_root);
        echo "Base: $base<br>";
        
        $include = str_replace($base,'include',$document_root);
        echo "Include: $include<br>";
        
        $os = strtolower(PHP_OS);
        echo "OS: $os<br>";

        $lk = ':';
        $org_include = ini_get("include_path");
        if(preg_match('/^win/i',$os))   $lk = ';';
        
        ini_set("include_path",$include.$lk.$org_include);
        echo "Include: ".ini_get("include_path")."<br>";
}

and let me see what it prints

-- 
regards,
Tom

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux