如何使用 PHP 从根开始包含

发布于 2024-08-19 02:04:34 字数 728 浏览 10 评论 0原文

我正在基于 SaaS 原则构建 CMS。我的网络服务器(动态专用)已启动并正在运行。一切都按预期进行,但现在我已经遇到了我的模板系统,后来又遇到了简单的事情,例如文件处理。从逻辑上讲,每个客户端都有一个自己的托管帐户。所有托管帐户都将向主数据库发出请求,该数据库托管在同一服务器上的大型全局帐户上。

稍后需要处理的一些事情是简单的事情,例如文件处理。通常,每个客户都会将他/她自己的数据存储在他/她自己的托管帐户中。只有页面数据和其他数据(产品目录、调查等)将托管在数据库中。

但在我能够从集中托管系统上传文件之前,我需要弄清楚如何访问指定的托管帐户。我已将所需的所有数据存储在会话变量中,当客户选择要使用的网站时,该变量将被填充(因为我的系统支持多个站点)。

我的服务器上的 url 结构如下: /home/[unix-user-name]/domains/[domain-name]/public_html/paths/to/the/folders/i/set/up/

网址中的第二部分是HostingAccountName,第四部分是来自客户端的域名。同样,我将此信息保存在会话变量中,可供访问。

我唯一的问题是,当客户端登录到系统时,基本网址的一部分已全部填充,如下所示:

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

我的问题,我如何强制 PHP 从根目录开始查找文件,在本例中为 home

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 large, 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

晚风撩人 2024-08-26 02:04:34

我不确定我是否正确解释了您的问题,但是您是否尝试过类似的操作:

chdir('/home/');

这将 PHP 的工作目录设置为 home,因此 PHP 会查找相对于该目录的包含文件。

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.

我的痛♀有谁懂 2024-08-26 02:04:34

/home 添加到 php.ini 中的 include_path 将允许 include*()require*() 获取 root 权限他们从那里进行搜索。

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

铁憨憨 2024-08-26 02:04:34

您可以设置如下内容:

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

include $includePath . 'myFile.php';

这允许它从根目录开始($_SERVER['DOCUMENT_ROOT']),然后根据需要进一步深入到子目录($subDir)。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文