Link to home
Start Free TrialLog in
Avatar of Robert Granlund
Robert GranlundFlag for United States of America

asked on

Absolute Path Root

When I run
<?php
echo __FILE__;
?>

Open in new window

to get the absolute path, I get this:
 D:\websites\M\mysite\

To enter that into a config file do I write it like:
/D/websites/M/mysite/  ???
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Uhh, why do you want the absolute path to the root?  That's a dependency I would not want in my programming.  You might choose $_ENV['DOCUMENT_ROOT'].  It would just depend on why you want to know this information.

But that said, you can find the context-appropriate directory separator slash in the PHP constant DIRECTORY_SEPARATOR.  Just use that in place of any hard-wired slash and you'll be OK even if your scripts are ported to different operating systems.
Avatar of Robert Granlund

ASKER

You went over my head Ray.
Let's deconstruct the problem.  Why (what business or technical reason) do you want the absolute path to the root?
I'm helping a friend install an image gallery to their website.  They bought the code and there is almost no documentation.  In the config file, it asks for the absolute path.
ASKER CERTIFIED SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Dave Baldwin
To make things more interesting, I know that on some web hosting you can not use the 'absolute path' because your directories are "chrooted" (?) so that you can only use paths inside your own directories.  Using an absolute can just result in an error.