?
Solved

Absolute Path Root

Posted on 2014-04-16
6
Medium Priority
?
195 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
Create CentOS 7 Newton Packstack Running Keystone

A bug was filed against RDO for the installation of Keystone v3. This guide is designed to walk you through the configuration for using Keystone v3 with Packstack. You will accomplish this using various repos and the Answers file.

 
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 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
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…
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 …
Suggested Courses

801 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