Including from another directory<

admin

Administrator
Staff member
I'm having troubles displaying files using the include function. The problem is I can't display files that are in a directory above it.

heres the code that I'm using



<! ---Start top part--- !>

<?PHP

//include header page
include '/head.html';



//include top banners
include '/top.htm';



print "<tr>";



//include the left menus
include '/left_menu.htm';

?>

<! ---End top part--- !>






<! ---Start top bar--- !>

<div align="center">
<td width="68%" align="left" valign="top">
<font face="arial" size="2">
<br><br>
<div align="left">
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="20" height="50" background="/images/bar_left.gif">
</td>
<td width="269" height="50" background="/images/bar_guestbook.gif">
</td>
<td width="30%" height="50" background="/images/bar_middle.gif">
</td>
<td width="20" height="50" background="/images/bar_right.gif">
</td>
</tr>
</table>
<br><br>

<! ---End top bar--- !>





<table width="98%" style="margin-left: 8px">
<tr>
<td>

<! ---Start page content--- !>

<p>Here are all the wonderful folks who have marked their territory on my site. If you'd like to sign it, click <a href=http://www.htmlforums.com/archive/index.php/"sign.php">here</a>.</p>

<?



//MySQL Variables. Edit where necessary
$host = "www.freesql.org";
$login_name = "guestbook_hyl";
$password = "clodhopper";

//Connecting to MYSQL
MySQL_connect("$host","$login_name","$password");



//select db

MySQL_select_db("guestbook_hyl") or die("Could not select database");

//output table with staff info
$query = mysql_query('SELECT * FROM guestbook');

WHILE ($row=mysql_fetch_array($query)) {
print "Name: {$row['name']} <BR>
E-mail: {$row['email']} <BR>
Website: {$row['url']} <BR>
Comments: {$row['comments']}<br><hr><br>
";}



?>



<! ---End page content--- !>





<! ---Don't change anyhing below here!--- !>

</td>
</tr>
</table>
</div>
</td>

<! ---Start bottom part--- !>

<?PHP

//include right menu
include '/right_menu.htm';



print "</tr><tr>";



//include footer
include '/bottom.html';


?>

<! ---End bottom part--- !>






</tr>
</table>
</div>
</body>
</HTML>

<! ---Page made by Alex Urquhart--- !>



The files I'm trying to display are in my home directory, and i've tried using
include 'http://mysite.com/menu.html';
and
include 'http://localhost/menu.html';


Any help at all would be welcomed.I think that the code is: include("menus.php");
or at least that's what I use. When I'm trying to go up a directory, I do this: <?php include("../menus.php"); ?>

It works fine for me.or use the full path

<?php include("/path/www/site.com/menus.php"); ?>Yeah...I think that the main thing is that you need the parenthesis since it is a function. I did a quick test by changing one of my includes to include "menus.php";instead of include("menus.php");
and it no longer worked.include and require are not functions, they are language contructs.

it shouldn't matter if they are in () or not. same as echo and printwith include you can go from root

include "/file.php";

you have to do the ../Thanks, I got it up using the ../ method.

Thanks again.
 
Back
Top