Solved

Absolute Path Root

Posted on 2014-04-16
6
189 Views
Last Modified: 2014-04-16
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/  ???
0
Comment
Question by:rgranlund
  • 3
  • 2
6 Comments
 
LVL 108

Expert Comment

by:Ray Paseur
Comment Utility
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.
0
 
LVL 7

Author Comment

by:rgranlund
Comment Utility
You went over my head Ray.
0
 
LVL 108

Expert Comment

by:Ray Paseur
Comment Utility
Let's deconstruct the problem.  Why (what business or technical reason) do you want the absolute path to the root?
0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 7

Author Comment

by:rgranlund
Comment Utility
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.
0
 
LVL 108

Accepted Solution

by:
Ray Paseur earned 260 total points
Comment Utility
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.
0
 
LVL 82

Expert Comment

by:Dave Baldwin
Comment Utility
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.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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…

728 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now