开发者

How to include from the very root with PHP

开发者 https://www.devze.com 2022-12-18 03:01 出处:网络
I\'m building a CMS on a SaaS principle. I have my webserver (dynamic dedicated) up and running. It\'s all going like expected, but now I\'ve come across my templating system, and later on simple thin

I'm building a CMS on a SaaS principle. I have my webserver (dynamic dedicated) up and running. It's all going like expected, but now I've come across my templating system, and later on simple things such as filehandling. Logically, each client has an own hostingaccount. All the hostingaccounts will be requesting to the masterdatabase, hosted on a larg开发者_StackOverflow社区e, global account, at the same server.

Some things which need to be handled later on are simple things as filehandling. Typically each client will store his/her own data at his/her own hostingaccount. Only the pagedata, and other data (productcatalogue, surveys, etc etc) will be hosted in the database.

But before I'm able to upload files from the centrally hosted system, I need to figure out how to get to the specified hostingaccount. I've got all the data I need stored in a sessionvariable which is filled when the client selects his/her website to work with (because my system supports mutliple sites).

The urlstructure on my server is like: /home/[unix-user-name]/domains/[domain-name]/public_html/paths/to/the/folders/i/set/up/

The second part in the url is the hostingaccountname, and the fourth part is de domain from the client. Again, I have this info in a session variable, ready for access.

My only problem is, when the client is logged on to the system, a part of the base url is allready filled like this:

/home/ontdek01/domains/ontdek5.nl/public_html/

My question, how can i force PHP to start looking for files from the very root, in this case home?


I'm not sure if I'm interpreting your question correctly, but have you tried something like:

chdir('/home/');

This sets PHP's working directory to home, so PHP looks for included files relative to that directory.


Adding /home to include_path in php.ini will allow include*() and require*() to root their searches from there.


you could set up something like:

$subDir = '/path/to/some/subdirectory/';
$includePath = $_SERVER['DOCUMENT_ROOT'] . $subDir;

include $includePath . 'myFile.php';

This allows it to start at the root down ($_SERVER['DOCUMENT_ROOT']) and then drill down further to a subdirectory if required ($subDir).

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号