Thursday, August 17, 2017 09:39 am EDT

Drupal Root Path To the File System

Bri's picture

If you are ever in need of the root path of your drupal installation as a file system path, you can use the constant DRUPAL_ROOT in Drupal 7.

This might come in handy for requiring files or includes that have different paths for different environments, such as local, staging, or production sites.

For example, when working locally on a mac, the contents of DRUPAL_ROOT might contain something like:

/Users/bri/Sites/MAMP/mysite

But when I want to put that code in production on a linux box, then the content of the DRUPAL_ROOT might be:

/var/www/mysite/html

Given that, I could create a traditional include or require statement such as:

require_once(DRUPAL_ROOT . '/sites/all/modules/mymodule/includes/myinclude.php');

Granted this particular example could be done using module_load_include() as well, knowing this constant could come in handy at times.

Comments

Anonymous's picture

Good one

Thanks for the wonderful suggestions and the coding techniques as well to create the Drupal template. That would be a www.assignmentuk.co.uk/write-my-assignment useful technique to enhance the website appearance the people must visit this for the development of their website

Anonymous's picture

Thank you so much for the

Thank you so much for the essays online information. As I was just looking for this and finally got it. thank you once again. You have easily explained the whole system. Now I will follow this exactly the same and hope my problem will be resolved. Have a nice weekend! Good bye!