gpt4 book ai didi

php - 冲突包括具有相对路径的文件

转载 作者:可可西里 更新时间:2023-11-01 01:05:06 24 4
gpt4 key购买 nike

我正在尝试在我的 php 脚本中动态包含。这是我的目录树:

-index.php
-sources/
--hello.php
--bye.php

在我的 index.php 中,我包含了 hello.php:

include("sources/hello.php");

在我的 hello.php 中,我还有另一个包含:

include("bye.php");

当我访问 index.php 时,它会抛出一条错误消息:

Message: require_once(bye.php) [function.require-once]: failed to open stream: No such file or directory

有没有办法让它工作但没有绝对路径?因为路径可以从一个目录更改到另一个目录但保持结构:

-index.php
-sources/
--hello.php
--bye.php

最佳答案

使用

dirname(__FILE__);

像这样

include(dirname(__FILE__)."/bye.php");

关于php - 冲突包括具有相对路径的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12926506/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com