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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • D. Alvarado

    #1

    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
  • Simon Stienen

    #2
    Re: How to get the document root (public html folder)?

    D. Alvarado <"D. Alvarado" <laredotornado@ zipmail.com>> wrote:[color=blue]
    > 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[/color]

    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($_SERV ER) should help you.
    --
    Simon Stienen <http://dangerouscat.ne t> <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

    Comment

    • Tony Marston

      #3
      Re: How to get the document root (public html folder)?


      "D. Alvarado" <laredotornado@ zipmail.com> wrote in message
      news:9fe1f2ad.0 409211958.64934 69f@posting.goo gle.com...[color=blue]
      > 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[/color]

      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

      This is Tony Marston's web site, containing personal information plus pages devoted to the Uniface 4GL development language, XML and XSL, PHP and MySQL, and a bit of COBOL




      Comment

      • Alvaro G. Vicario

        #4
        Re: How to get the document root (public html folder)?

        *** Tony Marston escribió/wrote (Wed, 22 Sep 2004 10:09:29 +0100):[color=blue]
        > 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()?[/color]

        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
        --

        Comment

        Working...