Zend Loader Problem - 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.

Related

Failed to open stream: No such file or directory, when using __DIR__

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';

phpsec lib path is not working from cron job

The file path for my script is
/var/www/html/MyProject/index.php
when I run the script as
~/./Myproject$ php index.php its runs perfectly
When I run the script as
~$ php /var/www/html/MyProject/index.php
It does not read the phpseclib file path
My index.php file is
<?php
include("crud.php");
include("functions.php");
set_include_path(get_include_path() . PATH_SEPARATOR . 'phpseclib');
include('Net/SFTP.php');
...
?>
error:
PHP Warning: include(Net/SFTP.php): failed to open stream: No such file or directory in /var/www/html/MyProject/index.php on line 6
PHP Warning: include(): Failed opening 'Net/SFTP.php' for inclusion (include_path='.:/usr/share/php:/usr/share/pear.:/usr/share/php:/usr/share/pear/phpseclib') in /var/www/html/MyProject/index.php on line 6
PHP Fatal error: Class 'Net_SFTP' not found in /var/www/html/MyProject/index.php on line 186
How to run the php script form cron job?
From the error message, you can see that phpseclib is not being added to the include path correctly. Try this for the set_include_path instead:
set_include_path(get_include_path() . PATH_SEPARATOR . __DIR__ . DIRECTORY_SEPARATOR . 'phpspeclib');
The __DIR__ will take into account the location of the file you're executing, rather than trying to find phpspeclib relative to the current working directory.
You can try placing phpseclib1.0.12 library to the /usr/share/ or if you are running from the Project then you can try adding like this:
set_include_path('/var/www/html/phpseclib1.0.12');
include('Net/SFTP.php');

php set_include_path drives me crazy

I need to include a file in php so I do
$web_proc = '../res/proc'; //variable read from config file I can't change
//in my file
include_once($web_proc . '/check_sprache.php');
and PHP outputs:
Warning: include_once(../res/proc/check_sprache.php): failed to open
stream: No such file or directory in
/Users/user/Sites/site/res/pdf/rechnung.php on line 62
Warning:
include_once(): Failed opening '../res/proc/check_sprache.php' for
inclusion (include_path='.:') in
/Users/user/Sites/site/res/pdf/rechnung.php on line 62
So I change the include path:
set_include_path(get_include_path() . PATH_SEPARATOR . dirname(__DIR__) . DIRECTORY_SEPARATOR);
and try it again, but PHP outputs:
Warning: include_once(../res/proc/check_sprache.php): failed to open
stream: No such file or directory in
/Users/user/Sites/site/res/pdf/rechnung.php on line 62
Warning:
include_once(): Failed opening '../res/proc/check_sprache.php' for
inclusion (include_path='.::/Users/user/Sites/site/res/') in
/Users/user/Sites/site/res/pdf/rechnung.php on line 62
But if if I do
include_once(dirname(__DIR__). DIRECTORY_SEPARATOR . $pfadweb_proc . '/check_sprache.php');
it works. But this is no solution, since the included file includes more files with a relative path, so they are alse not found.
So either I misunderstand the PHP include path, or it's just trolling me.
Can anybody help?
The include path looks odd in the second example; You have two PATH_SEPARATOR characters and a trailing DIRECTORY_SEPARATOR though I doubt this is the problem.
Try this one out instead
set_include_path(implode(PATH_SEPARATOR, [ // use array() if PHP < 5.4
dirname(__DIR__), // this should be /Users/user/Sites/site/res
get_include_path()
]));
include_once 'proc/check_sprache.php';
This will add the parent directory (/Users/user/Sites/site/res) of the CWD (/Users/user/Sites/site/res/pdf) to your include path.
Any include statements in any other files can use a relative path from /Users/user/Sites/site/res.

No such file or directory PHP Google Calendar

set_include_path("google-api-php-client/src/google");
require_once 'Client.php';
require_once '/Service/CalendarService.php';
Results in:
Warning: require_once(Google/Auth/AssertionCredentials.php): failed to open stream: No such file or directory in D:\xampp\htdocs\xampp\GoogleCalendar\google-api-php-client\src\Google\Client.php on line 18
Fatal error: require_once(): Failed opening required 'Google/Auth/AssertionCredentials.php' (include_path='google-api-php-client/src/google') in D:\xampp\htdocs\xampp\GoogleCalendar\google-api-php-client\src\Google\Client.php on line 18
Please let me know where I am going wrong.
Assuming I'm in my /home/user/analytics directory (a blank directory) when I download the analytics API through git:
git clone https://github.com/google/google-api-php-client.git
I get these errors when I try to use Client.php. I've modified
/home/user/analytics/google-api-php-client/src/Google/Client.php like so; add four lines before the require lines:
$dirArray = explode('/', dirname(__FILE__));
$homeDir = $dirArray[2];
$path = '/home/' . $homeDir . '/analytics/google-api-php-client/src/';
set_include_path(get_include_path() . PATH_SEPARATOR . $path);

Autoload Error: No such file or directory

I have included autoload.php in the header of my site
include 'vendor/autoload.php';
From this i am receiving the following errors on my site:
Warning: require_once(DIR/composer/autoload_real.php)
[function.require-once]: failed to open stream: No such file or
directory in
/homepages/6/d416629391/htdocs/leftovercheese/vendor/autoload.php on
line 5
Fatal error: require_once() [function.require]: Failed opening
required 'DIR/composer/autoload_real.php'
(include_path='.:/usr/lib/php5') in
/homepages/6/d416629391/htdocs/leftovercheese/vendor/autoload.php on
line 5
My code is:
// autoload.php generated by Composer
require_once __DIR__ . '/composer' . '/autoload_real.php';
return ComposerAutoloaderInit8be239f5caef32db03f87bb271ed6012::getLoader();
PHP Version: 5.2.17
Any ideas?
run composer install
That will import your packages and create the vendor folder as well as the autoload script. Also, make sure your relative path is correct.
You have to load vendor/autoload.php, which will autoload that file for you:
require_once __DIR__ . '/vendor/autoload.php';
This is assuming that your file is located at the same directory level as the vendor directory.
Otherwise, adjust.
For me, I updated some folder names and these updated are not reflected in autoload_files.php and autoload_static.php. I just had to run php composer.phar dump-autoload.

Categories