Jump to content

directory structure


1internet

Recommended Posts

So my site has a template, and each page plugs into it. But the pages are made dynamically, and some have directories, e.g. /directory/page, /directory2/page2, /directory2/sub-directory2/page3, etc.

If I want to include my template so the include function will display the template for every page, no matter how large the directory, how should it be coded?

I thought if I had

include '/template.php'

, then it would be the same as mydomain.com/template.php and work on every level, but this doesn't appear to be the case.

Link to comment
https://forums.phpfreaks.com/topic/273282-directory-structure/
Share on other sites

include $_SERVER['DOCUMENT_ROOT'].'/template.php';

 

When dealing with file paths in PHP, '/' refers to the file-system root, not the root of your domain.  You can determine the root of your domain using the $_SERVER['DOCUMENT_ROOT'] variable.

Link to comment
https://forums.phpfreaks.com/topic/273282-directory-structure/#findComment-1406489
Share on other sites

Yes, it's definitely the standard way to include files. There are alternatives for different circumstances.

 

And yes, it will work on your local server. It'll work anywhere so long as the DOCUMENT_ROOT is defined (it practically always is) and the path to the file from there is "/template.php" (it's in that directory). If your local setup is different and you need a subfolder, like "/mydomain/template.php", then it will not work because the path is different.

Link to comment
https://forums.phpfreaks.com/topic/273282-directory-structure/#findComment-1406520
Share on other sites

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.