Absolute Path Root

Posted on 2014-04-16
Last Modified: 2014-04-16
When I run
echo __FILE__;

Open in new window

to get the absolute path, I get this:

To enter that into a config file do I write it like:
/D/websites/M/mysite/  ???
Question by:rgranlund
  • 3
  • 2
LVL 109

Expert Comment

by:Ray Paseur
ID: 40003911
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.

Author Comment

ID: 40003929
You went over my head Ray.
LVL 109

Expert Comment

by:Ray Paseur
ID: 40003931
Let's deconstruct the problem.  Why (what business or technical reason) do you want the absolute path to the root?
Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.


Author Comment

ID: 40003946
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.
LVL 109

Accepted Solution

Ray Paseur earned 260 total points
ID: 40004044
Sorry to hear they bought code without documentation, since there are so many free PHP image galleries that have good documentation.  But that aside, it would probably be worth experimenting with a small subset of the images to see how things work.  There should be no requirement at all for an absolute path in an image gallery, and that makes me suspicious of the quality of the code.  The PHP file system functions produce slightly different results depending on your OS and configuration variables, so when you experiment with this sort of thing, var_dump() is your friend.  Just check to see what you're getting for the values of your base path.
LVL 83

Expert Comment

by:Dave Baldwin
ID: 40004594
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.

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

'Between' is such a common word we rarely think about it but in SQL it has a very specific definition we should be aware of. While most database vendors will have their own unique phrases to describe it (see references at end) the concept in common …
These days socially coordinated efforts have turned into a critical requirement for enterprises.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question