mme Posted April 21, 2008 Share Posted April 21, 2008 Hi I would like it so a varible is assigned to the http root <?php $myvar = getenv("DOCUMENT_ROOT"); ?> However I want the last directory to be removed eg; from /var/www/vhosts/mysite.com/httpdocs to /var/www/vhosts/mysite.com Thanks Quote Link to comment Share on other sites More sharing options...
DarkWater Posted April 22, 2008 Share Posted April 22, 2008 Change it in httpd.conf, not in a PHP script. Quote Link to comment Share on other sites More sharing options...
DarkWater Posted April 22, 2008 Share Posted April 22, 2008 Oh wait. Do you want to use it in the script without the last slash, or do you want to actually change the document root? Quote Link to comment Share on other sites More sharing options...
mme Posted April 22, 2008 Author Share Posted April 22, 2008 I want to use it in a script without the last directory and its slash. In my case without /httpdocs/ Quote Link to comment Share on other sites More sharing options...
DarkWater Posted April 22, 2008 Share Posted April 22, 2008 I want to use it in a script without the last directory and its slash. In my case without /httpdocs/ I might be wrong, but try this: $pos = strpos($myvar, 'httpdocs'); $newenv = substr($myvar, 0, $pos); echo $newenv; Quote Link to comment Share on other sites More sharing options...
DarkWater Posted April 22, 2008 Share Posted April 22, 2008 If you want it to read "/var/www/vhosts/mysite.com", use: $pos = strpos($myvar, 'httpdocs'); $newenv = substr($myvar, 0, $pos-1); echo $newenv; If you want it to read "/var/www/vhosts/mysite.com/", use: $pos = strpos($myvar, 'httpdocs'); $newenv = substr($myvar, 0, $pos); echo $newenv; Quote Link to comment Share on other sites More sharing options...
mme Posted April 22, 2008 Author Share Posted April 22, 2008 Thanks But what if I wanted to use this on another server that doesnt use httpdocs? without manual changes for each different server? Quote Link to comment Share on other sites More sharing options...
DarkWater Posted April 22, 2008 Share Posted April 22, 2008 Thanks But what if I wanted to use this on another server that doesnt use httpdocs? without manual changes for each different server? You'd need to code a function that analyzed the string and got the position of the last slash and removed it that way. I could code one I guess, if you really need it. Do you? Quote Link to comment Share on other sites More sharing options...
DarkWater Posted April 22, 2008 Share Posted April 22, 2008 function get_new_root() { $oldenv = get_env("DOCUMENT_ROOT"); $slashpos = strrpos($oldenv, "/"); if ($slashpos === false) { return false; } $newenv = substr($oldenv, 0, $slashpos); return $newenv; } Removes everything after the final slash. =) Should work on any server. Usage: $doc_root = get_new_root(); Returns FALSE if it can't find slashes. Quote Link to comment Share on other sites More sharing options...
mme Posted April 22, 2008 Author Share Posted April 22, 2008 Awesome Thanks so much Quote Link to comment Share on other sites More sharing options...
DarkWater Posted April 22, 2008 Share Posted April 22, 2008 It worked okay? I hope so. No problem, by the way. Quote Link to comment Share on other sites More sharing options...
trq Posted April 22, 2008 Share Posted April 22, 2008 <?php $myvar = realpath($_SERVER['DOCUMENT_ROOT']) . '/..'); ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.