By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,444 Members | 1,602 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,444 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a
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

P: n/a

"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

P: n/a
*** 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.