By tstclair on
This seems like a stupid question to me, but I have looked around quite a bit and can't find it.. How do I get the path to the drupal root directory? (there must be a function or predefined variable to do this, right??)
thanks.
Comments
I believe it is the function base_path().
I think base_path() should do the trick.
doesn't work...
Yeah, I thought that it would too, but for me it only returns '/', which is not the location of my drupal root directory. Is there some sort of file or environment variable I have to set?
well there is always
well there is always $_SERVER['DOCUMENT_ROOT'] from the PHP, could use that.
Using drupal's $base_url
Hi tstclair,
This is how i use $base_url for similar purposes:
And if your website is 'http://drupal.org' (for example) then you will get http://drupal.org/node/42042
Hope this will help.
Yes it did
I found this one very useful.
I got it printed on my login page.
<form action="<?php global $base_url;print $base_url; ?>/node?destination=node" method="post" id="user-login-form" accept-charset="UTF-8">getcwd() Gets the current
Gets the current working directory.
DRUPAL_ROOT
Use
DRUPAL_ROOT.It is defined in index.php as:
define('DRUPAL_ROOT', getcwd());This is in fact the first line that runs on every single page request.
DRUPAL_ROOT
DRUPAL_ROOTwas introduced in Drupal 7, well after this question was asked.hello
hello
I used DRUPAL_ROOT and it gave me /home/sairam1818/public_html/www.devotionalindia.com/newdevotionalindia
You can see that '/home/sairam1818/public_html/' needs to be replaced by 'http://'
so is there any function to get http://www.devotionindia.com/newdevotionalindia or i need to use str_replace function to deal with it.
one more suggestion i need:
what method should i use to get the above url if i am wrking with block.
Thanks
Ravi Bhadauria
https://www.admecindia.co.in
https://www.web-development-institute.com
https://www.graphic-design-institute.com
https://www.cadtraininginstitute.com
is there any function to get
Contact me to contract me for D7 -> D10/11 migrations.
This worked for me.
This worked for me.
I noticed that images were
I noticed that images were not appearing when following issue is there,
1. if image name contains any white space.
2. DRUPAL_ROOT gives '/home/sairam1818/public_html' instead 'http:/'
I found this below given solution, plz see it.
echo 'background:url('.str_replace('/home/sairam1818/public_html','http:/',DRUPAL_ROOT).'/sites/default/files/'.str_replace(' ', '%20', $getImg).')It manages whitespace in the image path and replaces the undesired value with http:/
Plz let me know if you have any doubts.
Thanks
Ravi Bhadauria
https://www.admecindia.co.in
https://www.web-development-institute.com
https://www.graphic-design-institute.com
https://www.cadtraininginstitute.com
You should read these documention
You should read these documention Global variable drupal 7
Logo linking to Homepage
global $base_url;print $base_url;Website logo always pointing to home page dynamically,this code works fine with drupal7.
Thank you!
This works perfectly for me. Thanks srikanth.g!
Interesting! Thanks!
Interesting! Thanks!