簡體   English   中英

通過set_include_path動態包含Google Api Client庫類

[英]Including Google Api Client library classes through set_include_path dynamically

我想在我的網站上使用“ google-api-php-client”類(並且我將其手動上傳到子文件夾Blog中的主機)以在我的網站上使用,我試圖通過“ 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中嘗試了此操作,但未成功將其設置到cPanel托管或托管提供程序中。

如果您的文件位於/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('google-api-php-client / autoload.php');

$ client = new Google_Client(); ...

現在我很好。 問題是我沒有為我的PHP 5.2版本使用正確版本的Google Api文件。 現在,我可以無縫實例化這些類。 非常感謝您的幫助。 :-)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM