PHP 中的相对、绝对和该死的量子路径!

发布于 2024-10-04 15:51:34 字数 480 浏览 0 评论 0原文

我正在构建一个网络应用程序(一个论坛),它将集成到各种网站中。这个想法是,存储所有文件的文件夹位置是可变的,以便 webmin 可以将论坛放在他们喜欢的任何地方。像往常一样,我有一些 PHP 包含文件。

假设我有 global.phpenvars.php 并希望将它们包含在 app_root.php 中。前两个存储在 ./global/ 中,相对于 app_root.php。现在,当我使用 ./ 时,我收到文件未找到错误。如果我只使用 global/ (没有前置斜杠),我会得到同样的错误。

我真的需要这方面的帮助:-(

路径需要相对于 app_root.php 并且不能是绝对的 - 每个安装的绝对路径都会有所不同。

感谢您的阅读,

James

I am building a web app (a forum), and it is to be integrated into various websites. The idea is that the folder location storing all the files is variable so that a webmin can put the forum wherever they like. I have, as usual, some PHP included files.

Say I have global.php and envars.php and want them included in app_root.php. The first two are stored in ./global/, relative to app_root.php. Now, when I use ./ I get a file not found error. If I use just global/ (no prepended slash), I get the same error.

I really need help on this :-(

The paths need to be relative to app_root.php and can't be absolute - the abs. path varies per installation.

Thanks for reading,

James

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

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

发布评论

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

评论(1

我恋#小黄人 2024-10-11 15:51:34

通常通过创建一个具有应用程序绝对路径的常量来解决此问题。

在你的 app_root.php 文件中类似的东西

define('ROOT_PATH', dirname(__FILE__));

然后,要包含其他文件,只需使用类似的东西

include ROOT_PATH . '/dir/file.php';

This problem is normally solved by creating a constant with an absolute path to the application.

Something like this in your app_root.php file

define('ROOT_PATH', dirname(__FILE__));

Then, to include other files just use something like

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