470,833 Members | 1,634 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,833 developers. It's quick & easy.

How to get the document root (public html folder)?

Hello, I am running PHP 4 on my Fedora Core 2 dev machine, Apache
1.31. I made a
lot of calls to $_SERVER['DOCUMENT_ROOT']. Unfortunately, when I move
my application to a Windows environment, running on an IIS web server,
the variable $_SERVER['DOCUMENT_ROOT'] is no longer supported (I
always get an empty string).

Question: What is a cross-web server way of finding the path to the
document root -- the path to the public html folder?

Thanks for your help, - Dave
Jul 17 '05 #1
3 4538
D. Alvarado <"D. Alvarado" <la***********@zipmail.com>> wrote:
Hello, I am running PHP 4 on my Fedora Core 2 dev machine, Apache
1.31. I made a
lot of calls to $_SERVER['DOCUMENT_ROOT']. Unfortunately, when I move
my application to a Windows environment, running on an IIS web server,
the variable $_SERVER['DOCUMENT_ROOT'] is no longer supported (I
always get an empty string).

Question: What is a cross-web server way of finding the path to the
document root -- the path to the public html folder?

Thanks for your help, - Dave


For most scripts you could try to obtain your current working directory and
remove the path given in REQUEST_URI (or maybe another one, that fits
better).

var_dump($_SERVER) should help you.
--
Simon Stienen <http://dangerouscat.net> <http://slashlife.de>
»What you do in this world is a matter of no consequence,
The question is, what can you make people believe that you have done.«
-- Sherlock Holmes in "A Study in Scarlet" by Sir Arthur Conan Doyle
Jul 17 '05 #2

"D. Alvarado" <la***********@zipmail.com> wrote in message
news:9f**************************@posting.google.c om...
Hello, I am running PHP 4 on my Fedora Core 2 dev machine, Apache
1.31. I made a
lot of calls to $_SERVER['DOCUMENT_ROOT']. Unfortunately, when I move
my application to a Windows environment, running on an IIS web server,
the variable $_SERVER['DOCUMENT_ROOT'] is no longer supported (I
always get an empty string).

Question: What is a cross-web server way of finding the path to the
document root -- the path to the public html folder?

Thanks for your help, - Dave


You must have something wrong with your server setup because I am running
PHP on Windows XP and all the $_SERVER variables are there. However, I am
running Apache, not IIS, so the fault must be with IIS. What shows up when
you run phpinfo()?

--
Tony Marston

http://www.tonymarston.net

Jul 17 '05 #3
*** Tony Marston escribió/wrote (Wed, 22 Sep 2004 10:09:29 +0100):
You must have something wrong with your server setup because I am running
PHP on Windows XP and all the $_SERVER variables are there. However, I am
running Apache, not IIS, so the fault must be with IIS. What shows up when
you run phpinfo()?


I believe you need to have PHP as Apache module to get the DOCUMENT_ROOT
variable. Otherwise, PHP has no way to know such details from virtual
hosts.

basedir() and $_SERVER['PHP_SELF'] can be a good start.
--
-+ Álvaro G. Vicario - Burgos, Spain
+- http://www.demogracia.com (la web de humor barnizada para la intemperie)
++ Las dudas informáticas recibidas por correo irán directas a la papelera
-+ I'm not a free help desk, please don't e-mail me your questions
--
Jul 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

10 posts views Thread by toufik toufik | last post: by
17 posts views Thread by rox.scott | last post: by
1 post views Thread by news.microsoft.com | last post: by
3 posts views Thread by Nalaka | last post: by
reply views Thread by mihailmihai484 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.