动态地包含通过set_include_path的Google Api客户端库类

时间:2016-02-02 00:35:47

标签: php path include set google-api-client

我想在我的网站上包含“google-api-php-client”(我手动上传到我的托管在子文件夹中)的类,我试图用“set_include_path”动态包含它功能。但是,当应用require_once时,我的代码停在那里,所以我没有包含它们。我展示了我为此目的测试的代码:

或者,您可以在代码中动态设置相同的ini指令。 set_include_path(get_include_path()path_separator'/ path / to / google-api-php-client / src'..);

我的代码:

// 1st try with the full path to the folder classes Google Api:
set_include_path (get_include_path (). path_separator. '/home/u140888/domains/segurosq.com/public_html/blog/google-api-php-client/src'))

// 2nd try with the route from the subfolder Blog to Google Api classes:
set_include_path (get_include_path () path_separator '/ blog / google-api-php-client / src'..);

// 3rd attempt the route from the folder with Google Api classes:
set_include_path (get_include_path () path_separator '/ google-api-php-client / src'..);

// This line require_once my code stops and you can not instantiate the class within Client.php because it has not been added successfully:
require_once 'Google / Client.php';

我甚至直接在include_path参数设置PHP.ini中尝试了这个,但没有成功。

2 个答案:

答案 0 :(得分:0)

如果您的文件位于/home/u140888/domains/segurosq.com/public_html/blog/,请尝试:

set_include_path(' /home/u140888/domains/segurosq.com/public_html/blog/google-api-php-client /' .PATH_SEPARATOR.get_include_path());

require_once('谷歌-API的PHP的客户端/ autoload.php&#39);

$ client = new Google_Client(); ...

答案 1 :(得分:0)

现在我很高兴。问题是我没有为我的PHP 5.2版本使用正确版本的Google Api文件。现在,我能够无缝地实现这些课程。谢谢你的帮助,我真的很感激。 : - )