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

x
?
Solved

using SITE_ROOT

Posted on 2009-12-21
16
Medium Priority
?
1,275 Views
Last Modified: 2012-05-08
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");

Open in new window

0
Comment
Question by:vicomin
  • 9
  • 7
16 Comments
 
LVL 1

Expert Comment

by:meno19
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

by:vicomin
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

by:meno19
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:vicomin
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

by:meno19
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

by:vicomin
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

by:vicomin
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

by:meno19
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

by:vicomin
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

by:meno19
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

by:vicomin
ID: 26107977
yes - it is killing me
0
 
LVL 1

Expert Comment

by:meno19
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

by:vicomin
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

by:vicomin
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');


I am calling everything from the admin/login.php page
<?php
require_once("../../includes/initialize.php");

this loads just fine
0
 

Author Comment

by:vicomin
ID: 26110042
when I log in I'm directed to the admin/index.php page

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

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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

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…
This article discusses how to create an extensible mechanism for linked drop downs.
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…
Suggested Courses
Course of the Month20 days, 10 hours left to enroll

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question