如何使用 PHP 从根开始包含
我正在基于 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我不确定我是否正确解释了您的问题,但是您是否尝试过类似的操作:
这将 PHP 的工作目录设置为 home,因此 PHP 会查找相对于该目录的包含文件。
I'm not sure if I'm interpreting your question correctly, but have you tried something like:
This sets PHP's working directory to home, so PHP looks for included files relative to that directory.
将
/home
添加到 php.ini 中的include_path
将允许include*()
和require*()
获取 root 权限他们从那里进行搜索。Adding
/home
toinclude_path
in php.ini will allowinclude*()
andrequire*()
to root their searches from there.您可以设置如下内容:
这允许它从根目录开始($_SERVER['DOCUMENT_ROOT']),然后根据需要进一步深入到子目录($subDir)。
you could set up something like:
This allows it to start at the root down ($_SERVER['DOCUMENT_ROOT']) and then drill down further to a subdirectory if required ($subDir).