Solved

Absolute Path Root

Posted on 2014-04-16
6
190 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 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.
0
 
LVL 7

Author Comment

by:rgranlund
ID: 40003929
You went over my head Ray.
0
 
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?
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
LVL 7

Author Comment

by:rgranlund
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.
0
 
LVL 109

Accepted Solution

by:
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.
0
 
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.
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
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 a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

809 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