www.webdeveloper.com
Results 1 to 4 of 4

Thread: include("/file.php") - document root

  1. #1
    Join Date
    Jul 2005
    Posts
    159

    include("/file.php") - document root

    I may be losing my mind. I swear I've been able to use something like
    PHP Code:
    include("/file.php"); 
    And it would grab file.php located in the document root no matter where that line of code was in the directory structure. But for the life of me I can't find an environment that respects that.

    I know there are a bizillion functions available on php.net for setting $_SERVER['document_root'] but I was hoping to avoid that by using the almighty single '/'.

    Am I losing my mind?

  2. #2
    Join Date
    Jun 2008
    Location
    Right Behind You
    Posts
    215
    Have you tried this?
    PHP Code:
    include("./file.php"); 

  3. #3
    Join Date
    Jul 2005
    Posts
    159
    Quote Originally Posted by ayvegh
    Have you tried this?
    PHP Code:
    include("./file.php"); 
    That will include a file at the same level as the current file. I'm asking if I had file A 8 directories deep in a site, and I wanted to include file B at the root of the site.. how could I do it with just a '/' as it does in html/css/etc ?

  4. #4
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,637
    PHP Code:
    include $_SERVER['DOCUMENT_ROOT'] . '/file.php'
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles