包括来自各种文件夹的文件

时间:2016-06-15 20:05:06

标签: php

这让我很头疼。我已经阅读了多个问题,但没有人帮助过我。

所以我需要包含来自不同文件夹的php文件。这是我的结构的样子。我正在使用WAMP。

/C
    /wamp
      /www
       /project1
        /main
         /backend
          -class.common.php
          -inc.config.php
            /providers
             /google
              -google.functions.php

从上面的结构可以看出,class.common.php位于文件夹后端(位于文件夹main下)。

现在,我尝试使用此代码在 google.functions.php 中加入 class.common.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

2 个答案:

答案 0 :(得分:1)

我不确定我是否正确阅读了你的图表,但考虑到以下因素:

如果def pingGetterLoop(): while(1): pingGetter() def mainLoop(): root.mainloop() print("thread two") threadTwo = Thread(target = mainLoop()) print("thread one") threadOne = Thread(target = pingGetterLoop()) threadOne.start() threadTwo.start() 的完整路径是

google.functions.php

C:/wamp/www/project1/main/backend/providers/google/google.functions.php 的完整路径是

class.common.php

要将该文件包含在相对位置,那么C:/wamp/www/project1/main/backend/class.common.php 应该可以正常工作

__DIR__

更新

从错误日志的外观来看,您有几个问题。

  • 包含失败发生在<?php include_once __DIR__.'/../../class.common.php'; 中,它调用路径相对包含C:\wamp\www\yele\main\backend\api_providers\rech\api_functions.php,该路径根据包含脚本的文件而变化。所以这对于供应商来说很奇怪,但您可以尝试将该行更改为include(../../_inc_config.php)以强制它包含相对于实际包含文件的内容,这恰好是我对您的问题的原始答案。
  • 重新声明include(__DIR__.'/../../_inc_config.php')课程时出现致命错误,因此请使用commoninclude_once

答案 1 :(得分:0)

第一,获得真实/物理路径可能更有用

include realpath('/../../class.common.php');
相关问题