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