I've been trying to fix this for 5 hours now.
This is my current php code.
set_include_path("google-api-php-client-master/src/Google");
require_once 'Google/Client.php';
require_once 'Google/Service/YouTube.php';
The directory structure looks like this:
+/test/
+google-api-php-client-master/
test.php
So the php file is in the same directory as the google api folder. Unfortunately I always get an error:
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
I have also set the permissions for the file. I am really clueless.
EDIT: I've tried some stuff out randomly and this solution worked for me:
set_include_path("api/src/");
require_once 'Google/Client.php';
require_once 'Google/Service/YouTube.php';
Zend recommends this procedure:
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';
Give it a try.
Try this
require_once 'Client.php';
require_once 'Service/YouTube.php';
Try commenting set_include_path() function - as it worked for me
<?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';
?>
Related
PHP is throwing this error when trying to access autoload: require_once __DIR__ . '/../vendor/autoload.php';
Warning:
require_once(/Applications/MAMP/htdocs/crud_app/public/vendor/autoload.php):
Failed to open stream: No such file or directory in
/Applications/MAMP/htdocs/crud_app/public/index.php on line 6
The thing is that if I echo __DIR__.'/../vendor/autoload.php'; it shows /Applications/MAMP/htdocs/crud_app/public and the vendor directory is outside of public.
This is the path where autoload.php is:
/Applications/MAMP/htdocs/crud_app/controllers/vendor/autoload.php
Any idea what is happening? This is my repo in case you want to look at it. Running PHP 8.1 and macOS. Thanks in advance.
index.php isn't inside controllers, you need to add that to the path.
require_once __DIR__ . '/../controllers/vendor/autoload.php';
I have this code:
require_once dirname(__DIR__).'/includes/db_connection.php';
to include a file from the root on a sub domain
but i am getting this error:
Warning: require_once(/home/integra/public_html/support/includes/db_connection.php): failed to open stream: No such file or directory
require_once dirname(__DIR__).'/includes/db_connection.php';
__DIR__ is not a root of the subdomain.
It is where current file is located.
You need:
require_once __DIR__.'/../includes/db_connection.php';
Also, dirname(__DIR__) makes no sense at all. It is equal to __DIR__.
This is my app. root:
htdocs
core/
init.php
classes/
DB.php
POST.php
ajax/
post_feeds.php
This is my post_feeds.php;
require_once '../core/init.php';
The file init.php is there but I don't understand why I am getting this error.
Warning: require_once(classes/DB.php): failed to open stream: No such file or directory in C:\Apache24\htdocs\core\init.php on line 9
Fatal error: require_once(): Failed opening required 'classes/DB.php' (include_path='.;C:\php\pear') in C:\Apache24\htdocs\core\init.php on line 9
It gives me no error in my init.php file when I require_once 'classes/DB.php';
This is init.php
session_start();
date_default_timezone_set('Etc/GMT+2');
//date_default_timezone_set('Europe/Tirane');
//autoload for classes.
require_once 'classes/DB.php';
require_once 'classes/USER.php';
require_once 'classes/NOTIFICATION.php';
if (isset($_COOKIE["user_id"])) {
$_SESSION['user_id'] = $_COOKIE['user_id'];
}
Try to use an absolute path for including files:
$root = realpath($_SERVER["DOCUMENT_ROOT"]);
require_once("{$root}/core/init.php");
Or with dirname:
require_once(dirname(__FILE__) .'/../core/init.php');
You dont have problem with including init.php, you have problem with init.php on line 9:
Warning: require_once(classes/DB.php): failed to open stream: No such file or directory in C:\Apache24\htdocs\core\init.php on line 9
Open init.php and change your path on line 9 from require_once('classes/DB.php') to require_once('../classes/DB.php').
DB.php is in classes folder in your root, and in line 9 on init.php you are including ROOT/core/classes/DB.php.
I have created and deployed a php app on heroku, but loading vendor is not working from config.php file. Checkout following...
config.php
require_once __DIR__ . '/vendor/autoload.php';
index.php
include('config/config.php');
Directory structure
config
--config.php
index.php
vendor
Its working on localhost but when i try to run after deploying to heroku, i get following error...
Warning: require_once(/app/config/vendor/autoload.php): failed to open stream: No such file or directory in /app/config/config.php on line 10 Fatal error: require_once(): Failed opening required '/app/config/vendor/autoload.php' (include_path='.:/app/.heroku/php/lib/php') in /app/config/config.php on line 10
Please help, i have tried google for an answer, but no luck. thanks
There is no way that works on localhost. __DIR__ points to the directory the current file is in, so in your case, that's config/, meaning you're including config/vendor/autoload.php.
You want a relative path instead:
require_once __DIR__ . '/../vendor/autoload.php';
Well this question maybe asked for hunderds time. But I could not make it work.
There is my directory list:
--main/
---- Zend/
---- dir1/
---- dir2/
And this is my set include path configuration:
set_include_path(PATH_SEPARATOR
. dirname(__FILE__) . DIRECTORY_SEPARATOR . 'Zend' . PATH_SEPARATOR
. get_include_path());
I also try adding all directories seperatly to the path.
But apache insists on giving these error:
Warning: require_once(Zend/Loader.php): failed to open stream: No such file or directory in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\main\Zend\Translate.php on line 25 Fatal error: require_once(): Failed opening required 'Zend/Loader.php' (include_path=';C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\main\Zend;.;C:\php\pear') in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\main\Zend\Translate.php on line 25
Which is thrown from the php file which is in dir1 on these lines:
include_once '../Zend/Locale.php';
include_once '../Zend/Translate.php'; //this is the line
How can I solve this problem?
As you have a relative to current file include path, one of the two Zend classes, which is running:
require_once 'Zend/Loader.php';
is resolving to htdocs\main\Zend\Zend\Loader.php
To fix, remove the DIRECTORY_SEPARATOR . 'Zend', then also your include_once's can be
require_once 'Zend/Locale.php';
require_once 'Zend/Translate.php';
Note I changed to require_once as include_once will carry on the script even if the include fails, which is not recommended.