473,397 Members | 2,084 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

How to get your site root via code

I've been following a tutorial from lynda.com (beyond the basics) - theres a page of code which defines your site root. But I cant seem to find the correct path - here is the code of initilize.php

PHP Code:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. // Define the core paths
  4. // Define them as absolute paths to make sure that require_once works as expected
  5.  
  6. // DIRECTORY_SEPARATOR is a PHP pre-defined constant
  7. // (\ for Windows, / for Unix)
  8. defined('DS') ? null : define('DS', DIRECTORY_SEPARATOR);
  9.  
  10. defined('SITE_ROOT') ? null :
  11.  
  12.  
  13.  
  14. define('SITE_ROOT', DS.'Users'.DS.'kevin'.DS.'Sites'.DS.'photo_gallery');
  15. //define('SITE_ROOT', DS.'home'.DS.'sites'.DS.'mydomain.com'.DS.'public_html');  THIS IS WHAT I TRIED BUT IT DOESNT WORK
  16. defined('LIB_PATH') ? null : define('LIB_PATH', SITE_ROOT.DS.'includes');
  17.  
  18. // load config file first
  19. require_once(LIB_PATH.DS.'config.php');
  20.  
  21. // load basic functions next so that everything after can use them
  22. require_once(LIB_PATH.DS.'functions.php');
  23.  
  24. // load core objects
  25. require_once(LIB_PATH.DS.'session.php');
  26. require_once(LIB_PATH.DS.'database.php');
  27.  
  28. // load database-related classes
  29. require_once(LIB_PATH.DS.'user.php');
  30.  
  31. ?>
My document root from phpinfo is /home/sites/mydomain.com/public_html/ - any help would be greatly appreciated.
Feb 15 '10 #1
4 7115
Dormilich
8,658 Expert Mod 8TB
what’s the string when you echo it?
Feb 15 '10 #2
u can user for apatchi for windows that code i think will be useful:
Expand|Select|Wrap|Line Numbers
  1. defined('DS') ? null : define ('DS' , DIRECTORY_SEPARATOR);
  2.  
  3. if (DS=='/') 
  4.   $absolute_path = dirname(__FILE__).'/'; 
  5. else 
  6.   $absolute_path = str_replace('\\', '/', dirname(__FILE__)).'/'; 
  7.  
  8. //echo $absolute_path;
  9. defined('SITE_ROOT') ? null : define ('SITE_ROOT' , $absolute_path);
  10. echo SITE_ROOT;
Oct 27 '10 #3
define('SITE_ROOT', DS.'Users'.DS.'kevin'.DS.'Sites'.DS.'photo_gallery ');

this statement is relative to Kevin's computer site root. If you are using Windows, then siteroot is automatically pointing to your server. So I changed mine to this way. I did not need to specify photo_gallery bc i did not use it within www. I just copied the working files from chapter 6 into my server root file, in such a case, it would be C:wamp\www

define('SITE_ROOT', DS.'wamp'.DS.'www');

if you are also working on learning php/mysql, let me know, maybe we can help each other out.
Oct 29 '10 #4
Dormilich
8,658 Expert Mod 8TB
I usually use
Expand|Select|Wrap|Line Numbers
  1. define("BASE_DIR", realpath(dirname(__FILE__) . '/..') . "/");
Oct 29 '10 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: John Roper | last post by:
Hi, I have an issues with my web app deployment project. The project actually has an ASP.NET site and a web service site, which are both destined to be virtual directories under a root website...
1
by: John | last post by:
Hi We have the html portion of our site in the site root folder on a remote site hosted with a web hosting company. I am now trying to add some asp.net bits to the site but in trying to keep...
11
by: Simon | last post by:
Hi all As I'm sure is common knowledge the version of IIS included in XP Pro is limited in that you can only create 1 website in the IIS snap in. As an ASP.net developer this is a pain in the...
0
by: Kenny | last post by:
I need to read/write .jpg files in a folder *above* the current site's root. If MapPath is the way to go, then how can I reference the desired folder as relative to the current site's root (I don't...
4
by: Jerry | last post by:
I'm having just a bit of trouble wrapping my brain around the task of working with folders that are above the site's root folder. I let users upload photos (.jpg/.gif files) which can...
1
by: Tim Wood | last post by:
I'm having trouble with setup of an asp.net application on Windows 2003. When I attempt to start the app I get "Server Error in '/MyApp' application. The message also says that error details cannot...
2
by: Pranab | last post by:
On my local sandbox , in IIS I created some Websites . Now when I try to create a ASP.NET web application , it tries to create it in the website last created and fails . But my requirement is...
5
by: Robert | last post by:
I have a series of web applications (configured as separate applications) on a server. There is a main application at the root and then several virtual directories that are independant...
8
by: news.microsoft.com | last post by:
I have two completely distinct ASP.NET (2.0) web applications. They share no code, they have distinct web.config files, they don't even link to each other. During development, they have lived...
3
by: Erik ETS | last post by:
I need some symmetry between my development environment and my running web site. The root of my web site is http://www.mysite.com/ while the root of the project in my local development environment...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.