Solved

# using SITE_ROOT

Posted on 2009-12-21
1,138 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

LVL 1

Expert Comment

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

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

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

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

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

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

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

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

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

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

Author Comment

yes - it is killing me
0

LVL 1

Expert Comment

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

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

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

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 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

### Suggested Solutions

A colleague recently asked me about how to give his client a small part of the web site that could be completely under the client's control.  Since I have done this sort of thing before to add emergency banners to a web site, I decided I would creat…
Consider the following scenario: You are working on a website and make something great - something that lets the server work with information submitted by your users. This could be anything, from a simple guestbook to a e-Money solution. But what…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…