android - Google API Client Library giving PHP error
I installed the Google API Client Library on my Ubuntu Server 16.04 using Composer and I am following up their guidance on their webpage.
Whenever, I need to verify a G suite account, I am including this code:
require_oncevendor/autoload.php
; But it is throwing a500 internal error
.
The details of the error are
<br /><b>Fatal error</b>: require_once(): Failed opening required '../../../../vendor/autoload.php' (include_path='.:/usr/share/php') in <b>/var/www/html/php/insert.php</b> on line <b>6</b><br />
I ran thefind . -name autoload.php
command, and found out that the file is located at./vendor/autoload.php
and because of that I am using therequire_once('../../../../vendor/autoload.php');
as it maps to the right path. Still, I get the error above.
I tried usingrequire_once __DIR__ . '/vendor/autoload.php'
as suggesed in the answer by Alex below, but I get the following error now.
<br /><b>Fatal error</b>: require_once(): Failed opening required '/var/www/html/php/vendor/autoload.php' (include_path='.:/usr/share/php') in <b>/var/www/html/php/insert.php</b> on line <b>6</b><br />
I need that file for the Library to run.
Answer
Solution:
Assuming
composer.json
is located in the same directory asinsert.php
, therequire
line should be like this:__DIR__
is translated to absolute path of the directory where current script is located, and'/vendor/autoload.php'
is a relative path from the directory to theautoload.php
.