Page 1 of 1

php include not working in other directories

Posted: Tue Feb 19, 2008 12:55 pm
by saturnstroll
Hello, I successfully used the include function on http://mrconcreteblockhouse.com/index.php which has 2 include files:

Code: Select all

<?php include("top.php"); ?>
and

Code: Select all

<?php include("bottom.php"); ?>
The index works just fine.

However when I try to put the same code in http://mrconcreteblockhouse.com/f/found ... b.html.php it doesn't work.
I then tried placing copies of top.php and bottom.php in the same /f/ directory, but still doesn't show the top or bottom.

Any ideas?

Re: php include not working in other directories

Posted: Tue Feb 19, 2008 1:01 pm
by Christopher
You might want to define the path to you directory and use it in your includes:

Code: Select all

<?php define('PATH', '/www/mysite/htdocs/'); ?>
 
<?php include(PATH . "top.php"); ?>

Re: php include not working in other directories

Posted: Tue Feb 19, 2008 2:13 pm
by saturnstroll
Hm I inserted the following at the top of the page in http://mrconcreteblockhouse.com/f/foundation-hub.html

Code: Select all

<?php define('PATH', '/www/mrconcreteblockhouse/httpdocs/'); ?>
 
<?php include(PATH . "top.php"); ?>
 
doesn't seem to work

Re: php include not working in other directories

Posted: Wed Feb 20, 2008 4:07 pm
by saturnstroll
Okay guys,
So I tried the "../" solution, which looks like this on /f/foundation-hub.html/

Code: Select all

<?php include ("../top.php"); ?>
No go. Maybe I didn't type it correctly?

Re: php include not working in other directories

Posted: Wed Feb 27, 2008 9:16 am
by saturnstroll
Problem solved. =)

Once I renamed the foundation-hub.html to foundation-hub.php, everything works with copies of top.php and bottom.php in said subdirectory.
Thanks to all for your input.