Author |
|
rahenkamp
Joined: 08 Aug 2006 Posts: 7
|
Posted: Wed 09 Aug '06 17:09 Post subject: php :: DOCUMENT_ROOT not working correctly |
|
|
Hi,
I just moved a bunch of code that I have from a MacOXS apache environment and for the includes that I use on the site I use require_once($_SERVER["DOCUMENT_ROOT]."/include/filename.php")
I am finding that this is not working as expected and since I am new to the Windows Apache environment I like to find out how you guys handle reletive referencing for include files.
TIA
d |
|
Back to top |
|
James Blond Moderator
Joined: 19 Jan 2006 Posts: 7374 Location: Germany, Next to Hamburg
|
Posted: Wed 09 Aug '06 17:14 Post subject: |
|
|
That is a bit tricky. It depence from the pathsetting in httpd.conf to run the script unter *nix, Windows, and Mac OS try
Code: |
$this_dir=substr($_SERVER['PHP_SELF'],0,strrpos($_SERVER['PHP_SELF'],"/")+1);
|
|
|
Back to top |
|
rahenkamp
Joined: 08 Aug 2006 Posts: 7
|
Posted: Wed 09 Aug '06 17:45 Post subject: |
|
|
James Blond wrote: | That is a bit tricky. It depence from the pathsetting in httpd.conf to run the script unter *nix, Windows, and Mac OS try
Code: |
$this_dir=substr($_SERVER['PHP_SELF'],0,strrpos($_SERVER['PHP_SELF'],"/")+1);
|
|
This does not quite work for me. I have the following folder structure.
ROOT |
|Grades|
index.php
| admin <-folders in grades
| classes
| includes
| faculty
| skins
if I use what I have always used ,which lets say, I need to load a skin I would have used:
include_once($_SERVER['DOCUMENT_ROOT']."/grades/skins/$SKIN/header.php");
which would have produced: (in the mac environment)
/library/webserver/documents/grades/skins/forestgreen/header.php
if I do a straight substitution of $_SERVER['DOCUMENT_ROOT'] with $this_dir from the code above I would get on the windows server this:
/grades/admin/skins/forestgreen/header.php
When I really need /grades/skins/forestgreen/header.php
If I directly use $_SERVER['DOCUMENT_ROOT'] in the windows environment I would get:
C:/Apache2/htdocs/grades/skins/forestgreen/footer.php
which is the correct physical path but when I do a require_once the script comes to a halt.
This is a HUGE problem for me if I can't resolve it.
Thanks again for your help
d |
|
Back to top |
|
pnllan
Joined: 05 Dec 2005 Posts: 221
|
Posted: Wed 09 Aug '06 18:22 Post subject: |
|
|
Per relative reference:
admin is a sub of grades right? If so, and I have a file in admin and want to refernce to a file in the docroot then:
../../aFileInTheDocroot.php
Next, if I have a file in admin and want to reference to the skinsfolder then:
../../skins/aFileInSkinsDir.php |
|
Back to top |
|
rahenkamp
Joined: 08 Aug 2006 Posts: 7
|
Posted: Wed 09 Aug '06 18:51 Post subject: |
|
|
pnllan wrote: | Per relative reference:
admin is a sub of grades right? If so, and I have a file in admin and want to refernce to a file in the docroot then:
../../aFileInTheDocroot.php
Next, if I have a file in admin and want to reference to the skinsfolder then:
../../skins/aFileInSkinsDir.php |
I have done that with no results and in fact is one of the ways I normally code. This is a new install as per the instructions on this site. Initially the install had some problems. I am totally stumped on this and I am under deadline to get it done.
Again my setup
root/grades
with
/admin
/classes
/includes
/skins
located in /grades
If I am trying to load a skin within the /admin folder I have always used:
include_once($_SERVER['DOCUMENT_ROOT']."/grades/skins/$SKIN/header.php");
If I do an echo($_SERVER['DOCUMENT_ROOT']."/grades/skins/$SKIN/header.php") in windows the result is:
c:/apache2/htdocs/grades/skins/forestgreen/header.php
which is the correct path but the include or require fails.
Grrrrrr
This works perfectly in MacOSX apache but breaks in Win apache. I am at my wits end on this. I have googled this till the cows come home and I am not getting any results.
Thanks
d |
|
Back to top |
|
pnllan
Joined: 05 Dec 2005 Posts: 221
|
Posted: Wed 09 Aug '06 19:07 Post subject: |
|
|
I understand your issue very well, and have seen it before. I would need to see the code, it has to be something in it. Most likely it is a sensitivity to paths (Mac v. Win) issue. Without seeing the code, use a PHP reference and note Windows specifics with regards to paths (require and include specifically).
If you post code, just post what is pertaint to this issue. |
|
Back to top |
|
rahenkamp
Joined: 08 Aug 2006 Posts: 7
|
Posted: Wed 09 Aug '06 19:53 Post subject: |
|
|
pnllan wrote: | I understand your issue very well, and have seen it before. I would need to see the code, it has to be something in it. Most likely it is a sensitivity to paths (Mac v. Win) issue. Without seeing the code, use a PHP reference and note Windows specifics with regards to paths (require and include specifically).
If you post code, just post what is pertaint to this issue. |
<?
$SKIN="forestgreen";
echo($_SERVER["DOCUMENT_ROOT"]."/grades/skins/$SKIN/footer.php");
include($_SERVER["DOCUMENT_ROOT"]."/grades/include/config.php");
include($_SERVER["DOCUMENT_ROOT"]."/grades/include/functions.php");
include($_SERVER["DOCUMENT_ROOT"]."/grades/skins/$SKIN/header.php");
?>
This only produced the result of the echo which is:
C:/Apache2/htdocs/grades/skins//footer.php
Please note that the variable $SKIN did not show in the result.
Nothing is included. ZIP, NADA
Since this is a new install do you thing that perhaps that is where the issue might lie?
Thanks
d |
|
Back to top |
|
pnllan
Joined: 05 Dec 2005 Posts: 221
|
Posted: Wed 09 Aug '06 20:55 Post subject: |
|
|
I just noticed that $SKIN is part of the string rather than being added to the string. What happens when you concatenate the variable SKIN as such:
Code: | echo($_SERVER["DOCUMENT_ROOT"]."/grades/skins/".$SKIN."/footer.php";
include($_SERVER["DOCUMENT_ROOT"]."/grades/include/config.php");
include($_SERVER["DOCUMENT_ROOT"]."/grades/include/functions.php");
include($_SERVER["DOCUMENT_ROOT"]."/grades/skins/".$SKIN."/header.php");
|
rather than:
echo($_SERVER["DOCUMENT_ROOT"]."/grades/skins/$SKIN/footer.php"
...
...
include($_SERVER["DOCUMENT_ROOT"]."/grades/skins/$SKIN/header.php");
You need to concatenate the Variable SKIN into the string like you did the GLOBAL Variable as shown in the above code block. |
|
Back to top |
|