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.
Related
I have this testing code
<?php
session_start();
require_once __DIR__ . '/src/Facebook/autoload.php';
$fb = new Facebook\Facebook
My folders structure is this:
http://localhost/facebook.php
If i test this page in a browser i receive:
Warning: require_once(C:\xampp\htdocs/src/Facebook/autoload.php): failed to open stream: No such file or directory in C:\xampp\htdocs\facebook.php on line 3
Fatal error: require_once(): Failed opening required 'C:\xampp\htdocs/src/Facebook/autoload.php' (include_path='C:\xampp\php\PEAR') in C:\xampp\htdocs\facebook.php on line 3
Create a folder named Facebook and put autoload.php inside that folder. What is happening here is your facebook.php file is trying to include/load a file named autoload.php and it can't be found there that's why you are getting this error.
I know, that's stupid, but I can't solve the problem with my project.
I wrote project on WAMP firstly and all works.
After, I try to migrate on live server, and find a problem - server don't require my files.
Project structure is:
application
core
Controller.php
Model.php
View.php
Route.php
models
views
controllers
included
config.php
app.php
index.php
when I try to run it, server return error:
Warning: require_once(core/model.php): failed to open stream: No such
file or directory in /home/u224052355/public_html/application/app.php
on line 4
This is the app.php code:
session_start();
require_once 'config.php';
require_once 'core/model.php';
require_once 'core/view.php';
require_once 'core/controller.php';
require_once 'core/route.php';
spl_autoload_register(function($class_name){
include 'included/' . $class_name . '.php';
});
Route::start();
When I try solve this by adding __DIR__ to require_once I gave this message:
Warning:
require_once(/home/u224052355/public_html/application/core/model.php):
failed to open stream: No such file or directory in
/home/u224052355/public_html/application/app.php on line 4
Fatal error: require_once(): Failed opening required
'/home/u224052355/public_html/application/core/model.php'
(include_path='.:/opt/php-5.5/pear') in
/home/u224052355/public_html/application/app.php on line 4
Using the $_SERVER['DOCUMENT_ROOT'] and etc. - same result.
How can I solve this problem?
Here is the structure of my application :
core
application
controller_base.class.php
registry.class.php
router.class.php
template.class.php
controller
include
config.php
model
views
index.php
The file config.php is included in the index.php file (there's no problem with this) and here is what it contains :
<?php
/*** include the controller class ***/
include(ROOT . '/core/application/controller_base.class.php');
/*** include the registry class ***/
include(ROOT . '/core/application/registry.class.php');
/*** include the router class ***/
include(ROOT . '/core/application/router.class.php');
/*** include the template class ***/
include(ROOT . '/core/application/template.class.php');
/*** autoload model classes ***/
function __autoload($class_name) {
$filename = strtolower($class_name) . '.class.php';
$file = ROOT . '/core/model/' . $filename;
if (!file_exists($file)) {
return false;
}
// include the $class_name class
include($file);
}
$registry = new registry;
You have to know that the constant ROOT is defined like this :
define('ROOT', str_replace('/index.php', '', $_SERVER['SCRIPT_NAME']));
This constant contains the value /Lab/Livre/POO/TP1 which is of course the root of the applications.
But there's a problem whith all the files I include in config.php. PHP throws me an error that says the files are not found in /Users/tom/www/Lab/Livre/POO/TP1/core/include/config.php.
So the problem is clear. I want PHP to look for the files from the root of the application (where index.php is), but it looks for it from the folder where config.php is located.
I had this problem for a long time but I want to find a solution once and for all.
I can't get it to do want I want ! I hope someone will help me.
Thank you very much.
P.S.: In other words, i want to include the files using an absolute path.
P.S.: Here is the full error text :
Warning: include(/Lab/Livre/POO/TP1/core/application/controller_base.class.php): failed to open stream: No such file or directory in /Users/tom/www/Lab/Livre/POO/TP1/core/include/config.php on line 4
Warning: include(): Failed opening '/Lab/Livre/POO/TP1/core/application/controller_base.class.php' for inclusion (include_path='.:/usr/local/php5/lib/php') in /Users/tom/www/Lab/Livre/POO/TP1/core/include/config.php on line 4
Warning: include(/Lab/Livre/POO/TP1/core/application/registry.class.php): failed to open stream: No such file or directory in /Users/tom/www/Lab/Livre/POO/TP1/core/include/config.php on line 7
Warning: include(): Failed opening '/Lab/Livre/POO/TP1/core/application/registry.class.php' for inclusion (include_path='.:/usr/local/php5/lib/php') in /Users/tom/www/Lab/Livre/POO/TP1/core/include/config.php on line 7
Warning: include(/Lab/Livre/POO/TP1/core/application/router.class.php): failed to open stream: No such file or directory in /Users/tom/www/Lab/Livre/POO/TP1/core/include/config.php on line 10
Warning: include(): Failed opening '/Lab/Livre/POO/TP1/core/application/router.class.php' for inclusion (include_path='.:/usr/local/php5/lib/php') in /Users/tom/www/Lab/Livre/POO/TP1/core/include/config.php on line 10
Warning: include(/Lab/Livre/POO/TP1/core/application/template.class.php): failed to open stream: No such file or directory in /Users/tom/www/Lab/Livre/POO/TP1/core/include/config.php on line 13
Warning: include(): Failed opening '/Lab/Livre/POO/TP1/core/application/template.class.php' for inclusion (include_path='.:/usr/local/php5/lib/php') in /Users/tom/www/Lab/Livre/POO/TP1/core/include/config.php on line 13
I have found a solution to my problem. I set the ROOT constant to this :
define('ROOT', $_SERVER['DOCUMENT_ROOT'] . str_replace('/index.php', '', $_SERVER['SCRIPT_NAME']));
But what went wrong ?
Getting this warning when trying to run my local PHP project (index.php):
Warning: require_once(/Controller/BulletinController.php): failed to open stream: No such file or directory in /Library/WebServer/Documents/WEBB_SERVER/6.2.1x/index.php on line 2
Fatal error: require_once(): Failed opening required '/Controller/BulletinController.php' (include_path='.:') in /Library/WebServer/Documents/WEBB_SERVER/6.2.1x/index.php on line 2
No such file or directory? This is my first 6 rows in index.php:
<?php
require_once ("/Controller/BulletinController.php");
require_once ("/General/MasterPage.php");
require_once ("./General/dbConnection.php");
session_start();
I've tried giving BulletinController.php 777 rights (just developing locally), but no luck.
This is what my structure looks like, so everything is in place:
Thankful for any advice you may have.
require_once ("/Controller/BulletinController.php");
must be
require_once ("Controller/BulletinController.php");
I think you need the whole path:
require_once dirname(__FILE__) . "/Controller/BulletinController.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__.