php include not working in other directories

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
saturnstroll
Forum Newbie
Posts: 8
Joined: Fri Aug 03, 2007 4:46 pm

php include not working in other directories

Post 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?
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: php include not working in other directories

Post 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"); ?>
(#10850)
saturnstroll
Forum Newbie
Posts: 8
Joined: Fri Aug 03, 2007 4:46 pm

Re: php include not working in other directories

Post 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
saturnstroll
Forum Newbie
Posts: 8
Joined: Fri Aug 03, 2007 4:46 pm

Re: php include not working in other directories

Post 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?
saturnstroll
Forum Newbie
Posts: 8
Joined: Fri Aug 03, 2007 4:46 pm

Re: php include not working in other directories

Post 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.
Post Reply