Jump to content

Include 'root' File From Subdirectory?


greg

Recommended Posts

How to include root files from subdirectory in php?

 

I have tried include '../configure.php'; but got error.

 

Also tried include($DOCUMENT_ROOT."../configure.php"); but same result.

 

For example, I have "root/admin" directory, and can't connect (from "/admin" dir)  to the file configure.php which is in root. There are also other files to include.

Link to comment
https://forums.phpfreaks.com/topic/258125-include-root-file-from-subdirectory/
Share on other sites

Not sure what your problem is. Using '../' should let you access files that are one level up from the file being executed.

 

The error you received should give you the FULL path to where the server is looking for the file. What WAS the error?

 

Assuming the below diagram is the structure in question, using '../configure.php' in the index.php file should work.

 

[ROOT]

|

|-- configure.php

|

|-[admin]

    |

    |-- index.php

Using '../' should let you access files that are one level up from the file being executed.

From the first file that was executed (generally). Subtle difference. Moral is to always use absolute paths whenever possible, either with the DOCUMENT_ROOT or the __FILE/DIR__ constants.

require_once($_SERVER["DOCUMENT_ROOT"] . "/configure.php");

Using '../' should let you access files that are one level up from the file being executed.

From the first file that was executed (generally). Subtle difference.

 

You're right. I considered that for 1/2 a second, but then second guessed myself and thought it didn't apply to this situation. But, now that I consider it, I don't know what I was thinking (or not thinking). That could very well be the problem.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.