base_path() not returning path to Drupal root
I have one other question I am pondering for a crazy long time - I wonder if it's a bug in the core...? An user has Drupal installed in www.example.com/foldera/folderb/ and in there a files folder ( thus www.example.com/foldera/folderb/files/ ) In my module, I need to determine the path to the 'files' folder relative to the domain name (example.com) So I've used file_directory_path() .. that gave me just 'files'. Then I've used base_path() hoping that it would give me /foldera/folderb/ this way base_path() . file_directory_path() but the result was /files I see this issue was discussed at length at http://lists.drupal.org/archives/support/2006-03/msg00042.html but there are no clear conclusions, and anyway, that's a thread from March 2006. So I wonder whether there is a clean solution for this. I'm on Drupal 5.2, btw. Tomas
More about this - I thought perhaps the user could manually set $base_url in his settings.php file. He did that -- but it did not solve the issue! See the messages from fuzzion at http://drupal.org/node/176939 Seems like a serious issue also for other users that have Drupal installed in subfolder(s), so I hope somebody comes back to me on this. Best regards, Tomas Tomas J. Fulopp wrote:
I have one other question I am pondering for a crazy long time - I wonder if it's a bug in the core...?
An user has Drupal installed in www.example.com/foldera/folderb/ and in there a files folder ( thus www.example.com/foldera/folderb/files/ )
In my module, I need to determine the path to the 'files' folder relative to the domain name (example.com)
So I've used file_directory_path() .. that gave me just 'files'. Then I've used base_path() hoping that it would give me /foldera/folderb/ this way base_path() . file_directory_path() but the result was /files
I see this issue was discussed at length at http://lists.drupal.org/archives/support/2006-03/msg00042.html but there are no clear conclusions, and anyway, that's a thread from March 2006. So I wonder whether there is a clean solution for this.
I'm on Drupal 5.2, btw.
Tomas
On 9/21/07, Tomas J. Fulopp <tomi@vacilando.org> wrote:
More about this - I thought perhaps the user could manually set $base_url in his settings.php file.
He did that -- but it did not solve the issue!
$base_url can't help with anything except fixing the internal paths and the menu links if they were wrong. If you change it, either the internal paths will break or you changed it to something equivalent.
See the messages from fuzzion at http://drupal.org/node/176939
Seems like a serious issue also for other users that have Drupal installed in subfolder(s), so I hope somebody comes back to me on this.
Best regards,
Tomas
Tomas J. Fulopp wrote:
I have one other question I am pondering for a crazy long time - I wonder if it's a bug in the core...?
An user has Drupal installed in www.example.com/foldera/folderb/ and in there a files folder ( thus www.example.com/foldera/folderb/files/ )
In my module, I need to determine the path to the 'files' folder relative to the domain name (example.com)
So I've used file_directory_path() .. that gave me just 'files'. Then I've used base_path() hoping that it would give me /foldera/folderb/ this way base_path() . file_directory_path() but the result was /files
I see this issue was discussed at length at http://lists.drupal.org/archives/support/2006-03/msg00042.html but there are no clear conclusions, and anyway, that's a thread from March 2006. So I wonder whether there is a clean solution for this.
I'm on Drupal 5.2, btw.
Tomas
On 9/21/07, Tomas J. Fulopp <tomi@vacilando.org> wrote:
I have one other question I am pondering for a crazy long time - I wonder if it's a bug in the core...?
An user has Drupal installed in www.example.com/foldera/folderb/ and in there a files folder ( thus www.example.com/foldera/folderb/files/ )
In my module, I need to determine the path to the 'files' folder relative to the domain name (example.com)
So I've used file_directory_path() .. that gave me just 'files'. Then I've used base_path() hoping that it would give me /foldera/folderb/ this way base_path() . file_directory_path() but the result was /files
file_directory_path() is a disk file path relative to drupal, and base_path() is an URL path. So, using base_path() . file_directory_path() - when I access the site as http://example.com/foldera/folderb it gives me "/foldera/folderb/files" - when I access the site as http://subdomain.example.com it give me "/files" But because it is an URL path, it is the same place and it works in both cases as far as the web browser is concerned. Is there a reason for your module to know the physical disk paths?
I see this issue was discussed at length at http://lists.drupal.org/archives/support/2006-03/msg00042.html but there are no clear conclusions, and anyway, that's a thread from March 2006. So I wonder whether there is a clean solution for this.
I'm on Drupal 5.2, btw.
Tomas
url(file_directory_path(), NULL, NULL, TRUE) but the usual case is that you have a path all the way to a file in which case you do url(file_create_path($path), NULL, NULL, TRUE) or somesuch. just working from memory. On 9/21/07, Cog Rusty <cog.rusty@gmail.com> wrote:
On 9/21/07, Tomas J. Fulopp <tomi@vacilando.org> wrote:
I have one other question I am pondering for a crazy long time - I wonder if it's a bug in the core...?
An user has Drupal installed in www.example.com/foldera/folderb/ and in there a files folder ( thus www.example.com/foldera/folderb/files/ )
In my module, I need to determine the path to the 'files' folder relative to the domain name (example.com)
So I've used file_directory_path() .. that gave me just 'files'. Then I've used base_path() hoping that it would give me /foldera/folderb/ this way base_path() . file_directory_path() but the result was /files
file_directory_path() is a disk file path relative to drupal, and base_path() is an URL path. So, using base_path() . file_directory_path()
- when I access the site as http://example.com/foldera/folderb it gives me "/foldera/folderb/files" - when I access the site as http://subdomain.example.com it give me "/files"
But because it is an URL path, it is the same place and it works in both cases as far as the web browser is concerned. Is there a reason for your module to know the physical disk paths?
I see this issue was discussed at length at http://lists.drupal.org/archives/support/2006-03/msg00042.html but there are no clear conclusions, and anyway, that's a thread from March 2006. So I wonder whether there is a clean solution for this.
I'm on Drupal 5.2, btw.
Tomas
Cog, That was not a solution. For http://example.com/foldera/folderb base_path() . file_directory_path() returns /foldera/folderb/files only if Drupal is installed in the root of example.com If Drupal is installed in folderb then base_path() . file_directory_path() returns /files and that means that the full link (in browser) is http://example.com/files which is the problem I described. I am trying Moshe's suggested solution that uses url(file_directory_path(), NULL, NULL, TRUE) which generates absolute http paths, which is a drawback, but I think it will be the solution. Cheers, Tomas Cog Rusty wrote:
On 9/21/07, Tomas J. Fulopp <tomi@vacilando.org> wrote:
I have one other question I am pondering for a crazy long time - I wonder if it's a bug in the core...?
An user has Drupal installed in www.example.com/foldera/folderb/ and in there a files folder ( thus www.example.com/foldera/folderb/files/ )
In my module, I need to determine the path to the 'files' folder relative to the domain name (example.com)
So I've used file_directory_path() .. that gave me just 'files'. Then I've used base_path() hoping that it would give me /foldera/folderb/ this way base_path() . file_directory_path() but the result was /files
file_directory_path() is a disk file path relative to drupal, and base_path() is an URL path. So, using base_path() . file_directory_path()
- when I access the site as http://example.com/foldera/folderb it gives me "/foldera/folderb/files" - when I access the site as http://subdomain.example.com it give me "/files"
But because it is an URL path, it is the same place and it works in both cases as far as the web browser is concerned. Is there a reason for your module to know the physical disk paths?
I see this issue was discussed at length at http://lists.drupal.org/archives/support/2006-03/msg00042.html but there are no clear conclusions, and anyway, that's a thread from March 2006. So I wonder whether there is a clean solution for this.
I'm on Drupal 5.2, btw.
Tomas
On 9/29/07, Tomas J. Fulopp <tomi@vacilando.org> wrote:
Cog,
That was not a solution. For http://example.com/foldera/folderb base_path() . file_directory_path() returns /foldera/folderb/files only if Drupal is installed in the root of example.com
Yes, that was clearly wrong. Probably just file_create_url() would be better.
If Drupal is installed in folderb then base_path() . file_directory_path() returns /files and that means that the full link (in browser) is http://example.com/files which is the problem I described.
I am trying Moshe's suggested solution that uses url(file_directory_path(), NULL, NULL, TRUE) which generates absolute http paths, which is a drawback, but I think it will be the solution.
This looks good, but don't forget to try it without Clean URLs.
Cheers,
Tomas
Cog Rusty wrote: On 9/21/07, Tomas J. Fulopp <tomi@vacilando.org> wrote:
I have one other question I am pondering for a crazy long time - I wonder if it's a bug in the core...?
An user has Drupal installed in www.example.com/foldera/folderb/ and in there a files folder ( thus www.example.com/foldera/folderb/files/ )
In my module, I need to determine the path to the 'files' folder relative to the domain name (example.com)
So I've used file_directory_path() .. that gave me just 'files'. Then I've used base_path() hoping that it would give me /foldera/folderb/ this way base_path() . file_directory_path() but the result was /files
file_directory_path() is a disk file path relative to drupal, and base_path() is an URL path. So, using base_path() . file_directory_path()
- when I access the site as http://example.com/foldera/folderb it gives me "/foldera/folderb/files" - when I access the site as http://subdomain.example.com it give me "/files"
But because it is an URL path, it is the same place and it works in both cases as far as the web browser is concerned. Is there a reason for your module to know the physical disk paths?
I see this issue was discussed at length at http://lists.drupal.org/archives/support/2006-03/msg00042.html but there are no clear conclusions, and anyway, that's a thread from March 2006. So I wonder whether there is a clean solution for this.
I'm on Drupal 5.2, btw.
Tomas
participants (3)
-
Cog Rusty -
Moshe Weitzman -
Tomas J. Fulopp