brian914 Posted June 6, 2012 Share Posted June 6, 2012 I am running MAMP and have a number of directories with different sites in my /Applications/MAMP/htdocs directory. The problem I am having is that inside one of those projects, I have a header file that gets included in pages that reside in different directories. So they need different paths for example for the style.css file. For example, from one file that path would be ../css/style.css but from another file inside another directory it would be ../../css/style.css. My question is if there is a way to set a "root" path for this projects, so I can use something like $root_dir . /css/style.css and it would always work, regardless of where in the site structure I am calling it from. Something similar to what wordpress does with TEMPLATEPATH. Quote Link to comment https://forums.phpfreaks.com/topic/263736-how-to-get-the-site-root-directory/ Share on other sites More sharing options...
requinix Posted June 6, 2012 Share Posted June 6, 2012 Have you considered setting up VirtualHosts for each of those sites? Then you wouldn't have to worry about paths. Quote Link to comment https://forums.phpfreaks.com/topic/263736-how-to-get-the-site-root-directory/#findComment-1351530 Share on other sites More sharing options...
brian914 Posted June 6, 2012 Author Share Posted June 6, 2012 Thanks a lot for the suggestion! I don't really know what I am doing... But I have created a virtual host now and I like this for a number of reasons already. Is the following the correct way to refer to my style sheet? Somehow it is not quite working yet, and I wonder if it might be from the space in client name? Here is how I am calling the style sheet: <link rel="stylesheet" href="<?php echo $_SERVER['DOCUMENT_ROOT']; ?>/css/style.css"> If I look at the source, here is what it looks like which is the correct path: (I changed the client name, but it is two works just like below) <link rel="stylesheet" href="/Users/brian/Documents/Client Name/6_WebFiles/css/style.css"> Why wouldn't this pull in the style sheet? Quote Link to comment https://forums.phpfreaks.com/topic/263736-how-to-get-the-site-root-directory/#findComment-1351533 Share on other sites More sharing options...
brian914 Posted June 6, 2012 Author Share Posted June 6, 2012 Could this be a permissions issue? And if so, what should it be and how do I set it? Quote Link to comment https://forums.phpfreaks.com/topic/263736-how-to-get-the-site-root-directory/#findComment-1351544 Share on other sites More sharing options...
requinix Posted June 7, 2012 Share Posted June 7, 2012 It's not permissions. You're mixing up two different but related concepts: file paths and URL paths. Quick primer: File paths are paths to actual files as they are on your computer. Using Windows as the best example of their differences, C:\Windows is a file path. In PHP you use file paths whenever you deal with include()ing scripts. URL paths are in URLs. Like right now I'm at /forums/index.php on the www.phpfreaks.com website. The relationship is about how the web server turns a URL into a file. "/forums/index.php" might translate into "C:\inetpub\phpfreaks\forums\index.php". You also can't confuse the two: I couldn't go to "www.phpfreaks.com/C:/inetpub/phpfreaks/forums/index.php", and in the code I couldn't include "http://www.phpfreaks.com/forums/index.php"; With that out of the way do you understand the problem? Because the DOCUMENT_ROOT is a file path, not a URL path. Quote Link to comment https://forums.phpfreaks.com/topic/263736-how-to-get-the-site-root-directory/#findComment-1351807 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.