View Full Version : root relative paths config
jonchakra5
11-22-2002, 01:30 AM
I'm hosting on a friends server and he has compliled PHP with vertual directories off (I believe that is the correct way to put it).
The problem is that I can't call files with include() or with opendir(), etc., with root relative paths such as include('/folder/foo.php');
We have solved this for the include() function by setting an include path in the .ini file, but this has limitations and does nothing for other functions apparently, and I don't see that we can configure paths for other functions at .ini, nor do I want to do this for every function I use.
Is there a way, short of recompiling, to set a root relative path for all php functions?
Thanks in advance!
jonchakra5
11-22-2002, 05:28 AM
I guess I may be looking for a way to turn on virtual directories without recompiling. Or some solution that allows for root relative paths in my PHP functions:
opendir('/foo/bar.php');
firepages
11-22-2002, 08:19 AM
you can alter the php.ini include_path at runtime i.e:
<?
ini_set("include_path",ini_get("include_path").";"."C:/path/to/your/doc/root");
?>
which may work ?
jonchakra5
11-22-2002, 07:30 PM
Thanks firepages! ..but...isn't that just setting the include path in the ini file?
We have solved this for the include() function by setting an include path in the .ini file but this has limitations and does nothing for other functions apparently
Would that do anything for the umpteen other functions that will use root relative paths such as
opendir('/foo/bar.php');
jonchakra5
11-23-2002, 12:37 AM
Looks like this is the solution I'm going with. It's not actually setting PHP up the way I want it, but it is clean and farely consise:
$root = $_SERVER['DOCUMENT_ROOT'];
include $root . '/folder/foo.php';
Nightfire
11-23-2002, 12:58 AM
Can't you just get your friend to change the path for you? Or am completely missing the point?
jonchakra5
11-23-2002, 01:20 AM
By changing the path, I can only assume you mean change the path for include() in the .ini file. Yes he can. That has drawbacks (can't use /foo/bar.php as a path, which is what I'm after, to name one), but it also does nothing for other functions.
Nightfire
11-23-2002, 02:07 AM
Ok, I seem to be confused by what you're asking, even everyone else is by the looks of it.... Explain in detail what you're wanting, show every error you get, show everything to us...
firepages
11-23-2002, 02:18 AM
Originally posted by jonchakra5
Would that do anything for the umpteen other functions that will use root relative paths such as
opendir('/foo/bar.php');
sorry it wouldn't no , I did not read your post correctly.
but if your include path had '.' as an option (just a period) then your relative includes should work, there is no PHP configuration that concerns file mapping as such that I know of.
jonchakra5
11-23-2002, 08:07 AM
First let me restate that I'm good to go onless someone feels they have a solution they feel strongly about. An explaination for Nightfire and anyone else not feelin' me yet however.
My vocabulary may be lacking, but I refer to ./ and ../ type pathing as "relative", and /foo/bar.php as "root relative". If I am in error there, forgive the limited vocab.
What I am looking to use is "root relative" paths in my includes and in my other PHP functions . I can not because of the compile time choices made already. Recompiling is not an option. So I have been searching for:
A) a way to get "root relative" paths fired up without recompiling, or
B) the most palitable alternative.
There are no error messages or such to relate. I am creating, not debugging.
A few posts up I posted what I am going with (a B solution, but quite adiquate to the task). So no need to further bang your head Nightfire, but thanks! I posted it so that anyone searching this thread would have my solution as I get frustrated when others say "found my own solution, thanks" and then cut out without sharing.
firepages - Thanks again for the efforts! Much apreciated!!
firepages
11-23-2002, 08:29 AM
Its much appreciated when members come back and let us know that an issue is resolved, or not or whatever,
I was , like, I asume Nightfire , was not 100% that you were happy with the current solution so I think thats just a simple misunderstanding, anyway glad you are on track :D
jonchakra5
11-23-2002, 10:06 AM
Me too. Thanks again bro'. And I will be back as I Got through my current project for sure.
brent3721
11-13-2006, 08:27 AM
I was able to get the root relative paths working (FINALLY). Assuming you setup your root directories for your sites with virtual hosts you can use
<?php include("includes/mainnav.php"); ?>
instead of
<?php include("/includes/mainnav.php"); ?>
and make sure you have /includes/ in your include path in your php.ini file:
include_path = ".:/php/includes:./includes:/includes/"
the above line shows include paths separated by colons, php puts this part in when looking for the file so it first looks for . (the current directory), then /includes, then ./includes (some of this stuff is redundant, I was messing around trying to get it to work for a while, but you get the point.)
hope this helps
b r e n t
brent@mimoymima.com
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.