Inside of a Drupal module I need to obtain the base path where the Drupal site is installed.
For example, if the drupal site is installed at: www.example.com/mysite/ then I want to get '/var/www/myseite'
If it is installed in: www.example.com/ then I want '/var/www'
What is the proper Drupal way to get this? I want to avoid PHP's server variables, as I read they are unreliable.
(Drupal 6 and Drupal 7)
In Drupal 7, there is a new constant called DRUPAL_ROOT which you can use for this.
To get the complete document root of the file system I use:
$_SERVER['DOCUMENT_ROOT'] . base_path()
On a Linux server you will get something like:
/var/www/html/www.example.com/mysite/
If you only use "base_path()", you will get only:
/mysite/
Same on Drupal 6 and 7.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With