include()

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

    #1

    include()

    I don't completely understand the documentation for the include() function:

    "Files for including are first looked in include_path relative to the
    current working directory and then in include_path relative to the directory
    of current script. E.g. if your include_path is ., current working directory
    is /www/, you included include/a.php and there is include "b.php" in that
    file, b.php is first looked in /www/ and then in /www/include/. "

    How do you know where "the current working directory" is?


  • Brion Vibber

    #2
    Re: include()

    Mike wrote:[color=blue]
    > How do you know where "the current working directory" is?[/color]

    If you mean, how do you find out programmaticall y what it is, use the
    getcwd() function.

    If you mean, how do you as a programmer know what it should be ahead of
    time, it's usually the directory containing the top-level script that's
    being executed. (This may not hold true for command-line execution, but
    should for web execution.)

    So if the web server is loading up A.php, and A.php include()s B.php, in
    B.php the working directory is still the location of A.php. (Unless of
    course you've used chdir() to change it.)

    -- brion vibber (brion @ pobox.com)

    Comment

    • Tony Marston

      #3
      Re: include()


      "Mike" <mikeotown@nosp am.msn.com> wrote in message
      news:adp0d.4394 1$Np2.9426@bign ews4.bellsouth. net...[color=blue]
      >I don't completely understand the documentation for the include() function:
      >
      > "Files for including are first looked in include_path relative to the
      > current working directory and then in include_path relative to the
      > directory
      > of current script. E.g. if your include_path is ., current working
      > directory
      > is /www/, you included include/a.php and there is include "b.php" in that
      > file, b.php is first looked in /www/ and then in /www/include/. "
      >
      > How do you know where "the current working directory" is?[/color]

      It is identified in $_SERVER['SCRIPT_FILENAM E']. It is the directory from
      which the current top-level script is being run. This directory does not
      change when you include() from another directory.

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

      Working...