【发布时间】:2016-06-15 20:05:05
【问题描述】:
这让我很头疼。我已经阅读了多个问题,但没有一个对我有帮助。
所以我需要包含来自不同文件夹的 php 文件。这是我的结构的样子。我正在使用 WAMP。
/C
/wamp
/www
/project1
/main
/backend
-class.common.php
-inc.config.php
/providers
/google
-google.functions.php
从上面的结构可以清楚地看出,class.common.php 在文件夹 backend 下(在文件夹 main 下)。
现在,我正在尝试使用此代码将 class.common.php 包含在 google.functions.php 中:-
include '../../class.common.php';
但是,这似乎不起作用。我什至尝试过使用__DIR__ 常量。没运气。实现我的结果最可靠的方法是什么?
PHP 错误日志。
[15-Jun-2016 22:16:25 Europe/Paris] PHP Warning: include(../../_inc_config.php): failed to open stream: No such file or directory in C:\wamp\www\yele\main\backend\api_providers\rech\api_functions.php on line 3
[15-Jun-2016 22:16:25 Europe/Paris] PHP Stack trace:
[15-Jun-2016 22:16:25 Europe/Paris] PHP 1. {main}() C:\wamp\www\yele\main\backend\ajax.php:0
[15-Jun-2016 22:16:25 Europe/Paris] PHP 2. include() C:\wamp\www\yele\main\backend\ajax.php:2
[15-Jun-2016 22:16:25 Europe/Paris] PHP 3. include() C:\wamp\www\yele\main\backend\class.apibase.php:3
[15-Jun-2016 22:16:25 Europe/Paris] PHP 4. include() C:\wamp\www\yele\main\backend\api_providers\rech\base_lib.php:2
[15-Jun-2016 22:16:25 Europe/Paris] PHP Warning: include(): Failed opening '../../_inc_config.php' for inclusion (include_path='.;C:\php\pear') in C:\wamp\www\yele\main\backend\api_providers\rech\api_functions.php on line 3
[15-Jun-2016 22:16:25 Europe/Paris] PHP Stack trace:
[15-Jun-2016 22:16:25 Europe/Paris] PHP 1. {main}() C:\wamp\www\yele\main\backend\ajax.php:0
[15-Jun-2016 22:16:25 Europe/Paris] PHP 2. include() C:\wamp\www\yele\main\backend\ajax.php:2
[15-Jun-2016 22:16:25 Europe/Paris] PHP 3. include() C:\wamp\www\yele\main\backend\class.apibase.php:3
[15-Jun-2016 22:16:25 Europe/Paris] PHP 4. include() C:\wamp\www\yele\main\backend\api_providers\rech\base_lib.php:2
[15-Jun-2016 22:16:25 Europe/Paris] PHP Fatal error: Cannot redeclare class common in C:\wamp\www\yele\main\backend\class.common.php on line 5
[15-Jun-2016 22:16:25 Europe/Paris] PHP Stack trace:
[15-Jun-2016 22:16:25 Europe/Paris] PHP 1. {main}() C:\wamp\www\yele\main\backend\ajax.php:0
[15-Jun-2016 22:16:25 Europe/Paris] PHP 2. include() C:\wamp\www\yele\main\backend\ajax.php:3
【问题讨论】:
-
将您的
includes 更改为include_once
标签: php