Page 1 of 1

Trouble Including Needed Files

Posted: Mon Jun 16, 2003 1:27 pm
by M$G
Hi
I've created this news script that I will eventualy relese publicly and have everything working greate however I am unable to include a file needed for one of the files that displays the news. For example I need to inclue a news.php files but in that file I need a config.php file. Here is the code for the news display includes:

Code: Select all

<?php
include "admin/config.php";

.... and so forth
?>
on my home page i need to include the newsdisp.php file by using

Code: Select all

<?php
include "/home/micro/public_html/projects/Mnews/mnewsDisplay.php";
?>
this leads to the problem... the config.php file is not included in the display file when I try to include it. It works great other wise.

Posted: Mon Jun 16, 2003 1:40 pm
by daven
include "admin/config.php" looks in your standard include directory (such as /etc/php4/includes) for the admin folder. Therefore, php is not finding the proper file.

To use another location, you must either hard-code it (ex: "/path/to/admin/config.php") or use relative paths (ex: "./admin/config.php"). Using "./" starts looking in the current directory, and "../" starts looking in the script's parent directory.

Posted: Mon Jun 16, 2003 1:44 pm
by delorian
You should include files giving a path from the highest file in the include tree:

e.g.

Code: Select all

/*
folder tree:
 index.php
 pages/news.php
 admin/config.php
*/

// so in index.php you have

include("pages/news.php");

// and in news.php you have

include("admin/config.php");
The all paths in news.php and config.php must be write in the way that they were in the index.php.