Jump to content

Archived

This topic is now archived and is closed to further replies.

wh33t

Windows and absolute paths?

Recommended Posts

Hey there, I'm sure this has been asked a few times but I cant for the life of me figure out what the problem would be called exactly.

I got php running on apache, and I see now that when i do something like

require('/inc/file.php');

my script no longer finds the file. It seems to think that the / means c:\ ... is there a way to tell Apache to work like linux? lol. Any push in the right direction would be great.

Share this post


Link to post
Share on other sites
Ps.

I dont want to have to put $_SERVER['DOCUMENT_ROOT'] everytime i wanna do an include.

Share this post


Link to post
Share on other sites
Use ./ rather than /

./ tells PHP to use the current working directory.

Share this post


Link to post
Share on other sites
Ummm, that doesn't work either. I'm trying to make it so I can reference the webroot by just using / like I could on a linux box. Is this not possible?

Share this post


Link to post
Share on other sites
I dont think so. I havn't seen this done. Just use relative paths.

Share this post


Link to post
Share on other sites
but if I include a file that includes a file relative paths dont work cause they are all relative to the file thats including them in the first place. :(

Share this post


Link to post
Share on other sites
This is where $_SERVER['DOCUMENT_ROOT'] comes in, if you dont want to type out $_SERVER['DOCUMENT_ROOT'] all the time then you can do this: $dr = $_SERVER['DOCUMENT_ROOT'];
then use $dr to referent the document root. like so:
include $dr . '/inc/file.php';

Share this post


Link to post
Share on other sites
ahh. well thats what I figured I was gonna have to do unless there was some sort of command directive i could toss into apache.

Ok well. if I do the documentroot thing it will run fine when i move it to the linux webspace right?

Share this post


Link to post
Share on other sites
Yeah it should do as $_SERVER['DOCUMENT_ROOT'] is set with the servers document root.

Share this post


Link to post
Share on other sites

×

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.