Hi i have the following directory structure:
Main Folder -> Classes -> user_classes
all nested in each other. I have the Following files inside Classes directory
always_include_top.php
custom_error_handler.php
config.php
database.php
Out of which the database.php file is as follows:
<?php
include_once("always_include_top.php");
include_once("config.php");
include_once("custom_error_handler.php");
include_once ("user_classes/newDatabase.php");
class Database extends newDatabase
{
// some more code... with extra functions
public function dbBackUp($backupfile = NULL)
{
//code...
}
}
?>
I have the Following file at User user_classes directory
newDatabase.php
The code sample for this file is
<?php
include_once("../always_include_top.php");
include_once("../config.php");
include_once("../custom_error_handler.php");
error_reporting(E_ALL);
class newDatabase
{
// my code goes here
}
?>
Why do i get the following error in classes/database.php ( No error in classes/user_classes/newDatabase.php )
Warning: include_once(../always_include_top.php)
[function.include-once]: failed to open stream: No such file or
directory in
E:\wamp\www\greeting_cards\adm\classes\user_classes\database.php on
line 2
Warning: include_once() [function.include]: Failed opening
'../always_include_top.php' for inclusion
(include_path='.;C:\php\pear') in
E:\wamp\www\greeting_cards\adm\classes\user_classes\database.php on
line 2
Warning: include_once(../config.php) [function.include-once]: failed
to open stream: No such file or directory in
E:\wamp\www\greeting_cards\adm\classes\user_classes\database.php on
line 4
Warning: include_once() [function.include]: Failed opening
'../config.php' for inclusion (include_path='.;C:\php\pear') in
E:\wamp\www\greeting_cards\adm\classes\user_classes\database.php on
line 4
Warning: include_once(../custom_error_handler.php)
[function.include-once]: failed to open stream: No such file or
directory in
E:\wamp\www\greeting_cards\adm\classes\user_classes\database.php on
line 5
Warning: include_once() [function.include]: Failed opening
'../custom_error_handler.php' for inclusion
(include_path='.;C:\php\pear') in
E:\wamp\www\greeting_cards\adm\classes\user_classes\database.php on
line 5
Fatal error: Cannot redeclare class Database in
E:\wamp\www\greeting_cards\adm\classes\database.php on line 12
I want both files to individually compile. As i would be including the files in other files based on page types. Whats the problem with including here?
When you use include_once(), it doesn't change to the directory where a particular file is located and execute it there, it executes the contents of that file within the context of the current file. So, classes/user_classes/database.php is executed as if it were in the classes folder. ".." refers to the Main folder in that case, so it's looking for the first three files in the Main folder. Those files aren't in the Main folder, so it gives you the warnings.
Related
You can see the error on http://orgdevelopers.tk/api/app/Config/core.php
my php version is 7.0.33.
I am getting this error when I execute my PHP file. Please help.
{Warning: require_once(/home/orgdevelopers.tk/public_html/ok/app/Config/constant.php): failed to open stream: No such file or directory in /home/orgdevelopers.tk/public_html/ok/core.php on line 3
Fatal error: require_once(): Failed opening required '/home/orgdevelopers.tk/public_html/ok/app/Config/constant.php' (include_path='.:/usr/local/lsws/lsphp70/share/pear:/usr/local/lsws/lsphp70/share/php:/usr/share/pear:/usr/share/php') in /home/orgdevelopers.tk/public_html/ok/core.php on line 3}
core.php line 3 is== require_once('app/Config/constant.php');
If both files reside in same directory, The path of constant.php in require_once function in core.php should be constant.php or /api/app/Config/constant.php or __DIR__.'/constant.php' instead of app/Config/constant.php
This is what is displayed in the browser when I try to open it:
Warning: require_once (/home/recoveryuganda/public_html/includes/defines.php):
failed to open stream: No such file or directory in /home/recoveryuganda/public_html/index.php on line 37
Fatal error: require_once():
Failed opening required '/home/recoveryuganda/public_html/includes/defines.php' (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/recoveryuganda/public_html/index.php on line 37
NO file exist in the path that specified, check, maybe you change the name, or moved to some other place the file.
just go to this directory:
/home/recoveryuganda/public_html/includes/
and find this file: defines.php
the problem is this file is missing/
if you have a backup of that file put it in that directory.
I created a config file that has a variable I want to use as a constant.
<?php
$ROOT_PATH = 'C:/Users/me/Documents/app-qas.com/site';
?>
On a CLASS page where I want to use the variable I added the following before instantiating the CLASS:
include_once("config.php");
$root=$ROOT_PATH;
I made the appropriate scoping changes to the functions in my class as follows:
global $root;
include_once($root."/Library/API/database.inc.php");
When I run my app, it DOES perform all of the data connections it
is designed to do, BUT it STILL returns the following errors:
Warning: include_once(config.php): failed to open stream: No such file
or directory in
C:/Users/me/Documents/app-qas.com/site'\class\Posting.class.php on
line 5
Warning: include_once(): Failed opening 'config.php' for inclusion
(include_path='.;C:\php\pear') in
C:/Users/me/Documents/app-qas.com/site'\class\Posting.class.php on
line 5
Notice: Undefined variable: ROOT_PATH in
C:/Users/me/Documents/app-qas.com/site'\class\Posting.class.php on
line 6
Warning: include_once(/Library/API/database.inc.php): failed to open
stream: No such file or directory in
C:/Users/me/Documents/app-qas.com/site'\class\Posting.class.php on
line 112
Warning: include_once(): Failed opening
'/Library/API/database.inc.php' for inclusion
(include_path='.;C:\php\pear') in
C:/Users/me/Documents/app-qas.com/site'\class\Posting.class.php on
line 112
Warning: include_once(/Library/API/database.inc.php): failed to open
stream: No such file or directory in
C:/Users/me/Documents/app-qas.com/site'\class\Posting.class.php on
line 112
Warning: include_once(): Failed opening
'/Library/API/database.inc.php' for inclusion
(include_path='.;C:\php\pear') in
C:/Users/me/Documents/app-qas.com/site'\class\Posting.class.php on
line 112
If I comment out the include and hard code the $root it runs like before BUT it DOES NOT throw any errors:
#include_once("joblaunch.php");
#$root=$ROOT_PATH;
$root='C:/Users/me/Documents/app-qas.com/site';
I don't understand why it runs and throws errors when getting the variable from the config.php but runs and doesn't throw an error when hard coding the path.
if you define a constant instead of a variable, this problem should be solved,
definition
old:
$ROOT_PATH = 'C:/Users/me/Documents/app-qas.com/site';
new:
define('ROOT_PATH', 'C:/Users/me/Documents/app-qas.com/site');
usage
old:
$root=$ROOT_PATH;
new:
$root = ROOT_PATH;
I have a site that I am have several issues with. I am not sure if the hosting company did changed something or the site was hacked. I hope this is OK as I have listed a list of errors when a user tries to register for the site. This is also happening when a user tries to use the search function, however in the search function the errors appear at the top and then the search results actually display below. The registration page does not show anything but the following errors.
Warning: include(dbconn.php): failed to open stream: No such file or directory in /home1/hoapres/public_html/users/register/index.php on line 26
Warning: include(dbconn.php): failed to open stream: No such file or directory in /home1/hoapres/public_html/users/register/index.php on line 26
Warning: include(): Failed opening 'dbconn.php' for inclusion (include_path='.:/opt/php54/lib/php') in /home1/hoapres/public_html/users/register/index.php on line 26
Warning: include(functions.php): failed to open stream: No such file or directory in /home1/hoapres/public_html/users/register/index.php on line 27
Warning: include(functions.php): failed to open stream: No such file or directory in /home1/hoapres/public_html/users/register/index.php on line 27
Warning: include(): Failed opening 'functions.php' for inclusion (include_path='.:/opt/php54/lib/php') in /home1/hoapres/public_html/users/register/index.php on line 27
Fatal error: Call to undefined function userText2Web() in /home1/hoapres/public_html/users/register/index.php on line 40
Without knowing your directory structure it is tricky to offer a precise answer, but the first thing I would do before trying to include files is to explicitly set your include path.
Assuming that the site root ( DOCUMENT_ROOT ) is /home1/hoapres/public_html and you have a folder for storing all your include files called includes, the path would be /home1/hoapres/public_html/includes
<?php
set_include_path( $_SERVER['DOCUMENT_ROOT'] . '/includes' );
if( !realpath( get_include_path() ) ) exit('Bad path');
/* Test to see what files exist perhaps */
print_r( glob( get_include_path() . '/*.*' ) );
/* Can you see the files you expect? */
include 'dbconn.php';
include 'functions.php';
?>
Your problem is include path you have used is not correct.
Please check your code where you have include the files like
include("dbconn.php");
you can try by this way
$fullpath = "http://yourdomain.com/";
if the dbconn.php is under any folder then
$fullpath = "http://yourdomain.com/foldername/";
include($fullpath."dbconn.php");
I'm trying out the zend framework classes for the first time. I am interested in using some of the individual classes for now.
Reading the documentation and some other q's here and in blogs I've tried three ways to load the classes
//attempt 1 - using zend loader
require_once('library\Zend\Loader.php');
Zend_Loader::loadClass('Zend_Date');
//attempt 2 - direct class load
require_once('library\Zend\Date.php');
// attempt 3 - auto load
set_include_path('D:\wamp\www\testPages\zend_test\library\Zend' . PATH_SEPARATOR . get_include_path());
require_once 'Loader\Autoloader.php';
$date = new Zend_Date();
// Output of the desired date
print $date->get();
my folder structure is:
zend_test(folder)
-- testLoad.php (the above code lives there)
-- library(folder)
--- zend(doler)
---- (the zend libs and sub folders)
I get the following error messages:
attempt 1
Warning: include(Zend\Date.php) [function.include]: failed to open stream: No such file or directory in D:\wamp\www\testPages\zend_test\library\Zend\Loader.php on line 83
Warning: include() [function.include]: Failed opening 'Zend\Date.php' for inclusion (include_path='.;C:\php5\pear') in D:\wamp\www\testPages\zend_test\library\Zend\Loader.php on line 83
Warning: require_once(Zend/Exception.php) [function.require-once]: failed to open stream: No such file or directory in D:\wamp\www\testPages\zend_test\library\Zend\Loader.php on line 87
Fatal error: require_once() [function.require]: Failed opening required 'Zend/Exception.php' (include_path='.;C:\php5\pear') in D:\wamp\www\testPages\zend_test\library\Zend\Loader.php on line 87
attempt2
Warning: require_once(Zend/Date/DateObject.php) [function.require-once]: failed to open stream: No such file or directory in D:\wamp\www\testPages\zend_test\library\Zend\Date.php on line 25
Fatal error: require_once() [function.require]: Failed opening required 'Zend/Date/DateObject.php' (include_path='.;C:\php5\pear') in D:\wamp\www\testPages\zend_test\library\Zend\Date.php on line 25
atempt3
Warning: require_once(Zend/Loader.php) [function.require-once]: failed to open stream: No such file or directory in D:\wamp\www\testPages\zend_test\library\Zend\Loader\Autoloader.php on line 24
Fatal error: require_once() [function.require]: Failed opening required 'Zend/Loader.php' (include_path='D:\wamp\www\testPages\zend_test\library\Zend;.;C:\php5\pear') in D:\wamp\www\testPages\zend_test\library\Zend\Loader\Autoloader.php on line 24
Am i missing something?
Your include path should read:
include_path='D:\wamp\www\testPages\zend_test\library;.;C:\php5\pear
When it tries to load the class Zend_Date it looks for a folder called Zend in the include path, with a file called Date.php in it.
All 3 of your methods should work with this corrected, and I recommend attempt 3.
used method 3 and did this to get it working:
set_include_path('D:/wamp/www/zendTest/library/');
require_once 'Zend/Loader/Autoloader.php';
Zend_Loader::loadClass('Zend_Date'); //or whatever zen class
in php.ini remove ";" before line include_Path and restart your wamp!