Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Absolute Path Root

Posted on 2014-04-16
6
Medium Priority
?
199 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 111

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 111

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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 111

Accepted Solution

by:
Ray Paseur earned 1040 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 84

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article discusses how to implement server side field validation and display customized error messages to the client.
An alternative to the "For XML" way of pivoting and concatenating result sets into strings, and an easy introduction to "common table expressions" (CTEs). Being someone who is always looking for alternatives to "work your data", I came across this …
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…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

604 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