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