[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
Solved

# using SITE_ROOT

Posted on 2009-12-21
Medium Priority
1,275 Views
hello I'm trying to use the php built in SITE_ROOT to set up my path linking and get the following error:

Warning: require_once(\Hosting\4761148\html\gallery\includes\config.php) [function.require-once]: failed to open stream: No such file or directory in D:\Hosting\4761148\html\gallery\includes\int.php on line 18

I'm on shared hosting with GoDaddy.

The config.php file is in the same folder as the int.php file so why doesn't it see it?

my site is set up as:
html/
gallery/
includes/
config.php
int.php

below is my code for the int.php file:
defined('DS') ? null : define('DS', DIRECTORY_SEPARATOR);

defined('SITE_ROOT') ? null :
define('SITE_ROOT', DS.'Hosting'.DS.'4760048'.DS.'html'.DS.'gallery');

defined('LIB_PATH') ? null : define('LIB_PATH', SITE_ROOT.DS.'includes');

require_once(LIB_PATH.DS."config.php");

0
Question by:vicomin
• 9
• 7

LVL 1

Expert Comment

ID: 26099774
It might be something with how you used the required once. You started it with "\Hosting" Your syntax might be off a bit. Try this below, also just direct it to the config from the root of the HTML folder.

require_once('gallery\includes\config.php');
0

Author Comment

ID: 26099876
okay this works but it doesn't make use fo the LIB_PATH.DS

//require_once(LIB_PATH.DS."config.php");
require_once('config.php'); //******** works fine

now it fails here:

require_once(LIB_PATH.DS."functions.php");

I changed the SITE_ROOT to:
defined('SITE_ROOT') ? null : define('SITE_ROOT', DS.'gallery');
defined('LIB_PATH') ? null : define('LIB_PATH', SITE_ROOT.DS.'includes');

0

LVL 1

Expert Comment

ID: 26099927
Okay try this. I think it does not like how the SITE_ROOT is getting called.

defined('SITE_ROOT') ? null : define('SITE_ROOT', DS.'gallery');
defined('LIB_PATH') ? null : define('LIB_PATH', 'SITE_ROOT',DS.'includes');
0

Author Comment

ID: 26100859
i believe that helped some. however, i still get an error. in the includes folder i have the following files:
config.php
int.php
user.php
db.php
ses.php

on the int.php file I am trying to load them as: config, ses, db then user.

on the user file i have: require_once(LIB_PATH.DS."database.php");

I get the following error:

Warning: require_once(\gallery\includes\database.php) [function.require-once]: failed to open stream: No such file or directory in D:\Hosting\4761148\html\gallery\includes\user.php on line 2

Fatal error: require_once() [function.require]: Failed opening required '\gallery\includes\database.php' (include_path='.;C:\php5\pear') in D:\Hosting\4761148\html\gallery\includes\user.php on line 2

line 2 on user is:
require_once(LIB_PATH.DS."database.php");

if i comment it out it works fine. I'm using the same line of code on the database.php file to include the config.php file.
require_once(LIB_PATH.DS."config.php");

so why does it fail?

0

LVL 1

Expert Comment

ID: 26100868
It looks like it's trying to find the database.php file as from the files you listed in the include folder database.php does not exist. Where does the database.php file exist?
0

Author Comment

ID: 26101072
it is in the same folder - right next to it

so i reviewed the int.php file and did the following:

defined('DS') ? null : define('DS', DIRECTORY_SEPARATOR);
defined('SITE_ROOT') ? null : define('SITE_ROOT', DS.'gallery');
defined('LIB_PATH') ? null : define('LIB_PATH', SITE_ROOT.DS.'includes');

require_once(LIB_PATH.DS.'config.php');

Error now:
Warning: require_once(\gallery\includes\config.php) [function.require-once]: failed to open stream: No such file or directory in D:\Hosting\4761148\html\gallery\includes\int.php on line 11

Fatal error: require_once() [function.require]: Failed opening required '\gallery\includes\config.php' (include_path='.;C:\php5\pear') in D:\Hosting\4761148\html\photo-gallery\includes\int.php on line 11

line 11 is:
require_once(LIB_PATH.DS.'config.php');

0

Author Comment

ID: 26101081
i'm confused - why can't it find a file next to it?
is the DIRECTORY_SEPARATOR not working right?
0

LVL 1

Expert Comment

ID: 26101422
Your Directory Separator is working fine but when your calling the files it cannot find them from where you are calling them from. This site root function does not seem to be working, it does seem to be working just as a variable though.

The below code wont work cause you are telling the int.php file that the config.php file is within the \gallery\includes\ folder from within the includes folder. When the config folder is not within anything its in the same folder so the code should just be require_once('config.php');

defined('DS') ? null : define('DS', DIRECTORY_SEPARATOR);
defined('SITE_ROOT') ? null : define('SITE_ROOT', DS.'gallery');
defined('LIB_PATH') ? null : define('LIB_PATH', SITE_ROOT.DS.'includes');

require_once(LIB_PATH.DS.'config.php');
0

Author Comment

ID: 26101649
I'm bad with pathes - get me all the time.

defined('SITE_ROOT') ? null : define('SITE_ROOT', DS.'photo-gallery');

should be operating as such:
if siteroot is null then define it as such:
echo SITE_ROOT; \\ prints  \gallery

echo LIB_PATH; // \gallery\includes
echo LIB_PATH.DS; // \gallery\includes\
echo LIB_PATH.DS.'config.php'; // \gallery\includes\\gallery\includes\config.php

that's an issue.

I'm using a file at: http://www.site.com/gallery/public/admin/index.php
the index file is:
<?php
require_once("../../includes/initialize.php");

0

LVL 1

Expert Comment

ID: 26107103
It looks as if you just need to fix the paths that you are calling. Are you still having the problem.
0

Author Comment

ID: 26107977
yes - it is killing me
0

LVL 1

Expert Comment

ID: 26108092
Okay which parts are you getting errors on. I can help but list out the places where you are getting errors. In the initialize.php doc change this line

require_once(LIB_PATH.DS.'config.php');

to

require_once('config.php');
0

Author Comment

ID: 26110010
thanks

i did that on the int page for:

require_once('config.php');

require_once('functions.php');

require_once('session.php');
require_once('database.php');

require_once('user.php');
0

Author Comment

ID: 26110032
i did the same changes to the following files:

database.php
//require_once(LIB_PATH.DS."config.php");
require_once('config.php');

user.php
//require_once(LIB_PATH.DS.'database.php');
require_once('database.php');

<?php
require_once("../../includes/initialize.php");

0

Author Comment

ID: 26110042

which looks like this:
<?php
require_once("../../includes/initialize.php");
if (!$session->is_logged_in()) { redirect_to("login.php"); } include_layout_template('admin_header.php'); ?> Menu </div> <p> <?php include_layout_template('admin_footer.php'); ?> the include_layout_template is a function in the functions.php file that is two levels up function include_layout_template($template="")
{
include(SITE_ROOT.DS.'public'.DS.'layouts'.DS.$template); } it blows up here on the index.php file when making this call to load the header include 0 LVL 1 Accepted Solution meno19 earned 2000 total points ID: 26112296 I gotta say I think your includes are way more complicated then they need to be. I get what you are trying to do but I do agree it is confusing. To debug this you need to see what is being returned with the function include_layout_template($template=""). Echo this and lets see what string is returned. From their we just need to rewrite it so that it is point to the correct directory. I think that it is just point to the wrong place.
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…