【问题标题】:require once - PHP: set_include_path not working需要一次 - PHP:set_include_path 不起作用
【发布时间】:2014-09-15 22:22:04
【问题描述】:

我已经尝试修复此问题 5 个小时了。

这是我当前的 php 代码。

set_include_path("google-api-php-client-master/src/Google");
require_once 'Google/Client.php';
require_once 'Google/Service/YouTube.php';

目录结构如下:

+/test/
    +google-api-php-client-master/
        test.php

所以 php 文件与 google api 文件夹位于同一目录中。不幸的是,我总是收到错误:

Warning: require_once(Google/Client.php) [function.require-once]: failed to open stream: No such file or directory in /test/test.php on line 20

Fatal error: require_once() [function.require]: Failed opening required 'Google/Client.php' (include_path='google-api-php-client/src') in /test/test.php on line 20

我还设置了文件的权限。我真是一头雾水。

编辑:我随机尝试了一些东西,这个解决方案对我有用:

set_include_path("api/src/");
require_once 'Google/Client.php';
require_once 'Google/Service/YouTube.php';

【问题讨论】:

    标签: php youtube-api include-path require-once


    【解决方案1】:

    Zend 推荐这个程序:

    defined('BASE_PATH')
        || define('BASE_PATH', realpath(dirname(__FILE__));
    
    set_include_path(implode(PATH_SEPARATOR, array(
        realpath(BASE_PATH . '/Google'),
        get_include_path(),
    )));
    
    require_once 'Client.php';
    

    试一试。

    【讨论】:

    • 丢失的文件在哪里?向我们展示一个完整的树视图,包括 Client.php 和 YouTube.php。
    【解决方案2】:

    试试这个

    require_once 'Client.php';
    require_once 'Service/YouTube.php';
    

    【讨论】:

    • 不幸的是它仍然没有帮助。
    • 请显示您目录的详细树形结构
    • \test\google-api-php-client-master\src\Google\Client.php \test\google-api-php-client-master\src\Google\Service\Youtube.php \test\test.php
    【解决方案3】:

    尝试评论 set_include_path() 函数 - 因为它对我有用

    <?php 
        // Call set_include_path() as needed to point to your client library.
        include_once 'includes/session_manager.php';
        require_once 'Google/Client.php';
        require_once 'Google/Service/YouTube.php';
    ?> 
    

    【讨论】:

    • “评论”函数到底是什么意思?我应该把它放在评论中吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-02
    相关资源
    最近更新 更多