Page 1 of 1
include() problems
Posted: Mon Dec 01, 2003 1:25 am
by Pyrite
I can't seem to include php files that are in different directories.
Most of my php files are in:
/cms
And if I include other php files that are in /cms or subdirectories in /cms, no problem.
But I need to be able include files that are in /cms from other directories on the server like:
/language/en/foo/bar/car/
So like file /language/en/foo/bar/car/exam1.php needs to be able to include /cms/includes/config.php (which has the db settings and ADOdb object).
But when I do, I get include() warnings and errors..
I think its my include path in my php.ini, but I can't figure out what to set it to.
I'm using Apache 2.x on Server 2003 with php 4.3.3
Thx.
Posted: Mon Dec 01, 2003 1:31 am
by infolock
so you tried
Code: Select all
include("../../../../../cms/includes/config.php");
?
Posted: Mon Dec 01, 2003 1:40 am
by Pyrite
Yes, I tried that and include("/cms/includes/config.php"); also. Neither worked.
Posted: Mon Dec 01, 2003 1:53 am
by Pyrite
When I try including with the absolute path include("/cms/includes/config.php");
I get this errors..
Code: Select all
Warning: main(/cms/includes/config.php): failed to open stream: No such file or directory in E:\www\ibs\language\en\curriculum\courses\romansgalatians\unit02\lesson03\1stQ_Exam.php on line 2
Warning: main(): Failed opening '/cms/includes/config.php' for inclusion (include_path='.;c:\php\includes;\cms\includes;'') in E:\www\ibs\language\en\curriculum\courses\romansgalatians\unit02\lesson03\1stQ_Exam.php on line 2
And when I include with the relative path, I get this:
Code: Select all
Warning: main(../../../../../../cms/includes/config.php): failed to open stream: No such file or directory in E:\www\ibs\language\en\curriculum\courses\romansgalatians\unit02\lesson03\1stQ_Exam.php on line 2
Warning: main(): Failed opening '../../../../../../cms/includes/config.php' for inclusion (include_path='.;c:\php\includes;\cms\includes;'') in E:\www\ibs\language\en\curriculum\courses\romansgalatians\unit02\lesson03\1stQ_Exam.php on line 2
Really, I'd like to be able to use the absolute path include if I can.
Posted: Mon Dec 01, 2003 1:59 am
by Nay
mMm.......get the path of a file with:
Code: Select all
<?php
echo realpath("config.php");
?>
Place, that script where config.php is, then use that path. It should work.
-Nay
Posted: Mon Dec 01, 2003 2:00 am
by Pyrite
My config.php looks like:
Code: Select all
<?php
include("extention.inc");
// Include the ADODB DB Class
include('adodb/adodb.inc.'.$phpEx);
// The Database Parameters
$dbhost = "localhost";
$dbuser = "myusername";
$dbpass = "mypassword";
$dbname = "ibs";
// Dont edit past here
$db = NewADOConnection('mysql');
$db->debug = false;
$db->Connect($dbhost, $dbuser, $dbpass, $dbname);
?>
Posted: Mon Dec 01, 2003 2:13 am
by Pyrite
Nay wrote:mMm.......get the path of a file with:
Code: Select all
<?php
echo realpath("config.php");
?>
Place, that script where config.php is, then use that path. It should work.
-Nay
Ok, I did that and included the file with:
include("e:\www\ibs\cms\includes\config.php");
And it worked, but the include statements inside of config.php also errored out. Besides, I really don't want to use that kind of include path. If I every move my code, I'll have to change all the scripts. No thanks. Theres gotta be another way.
Posted: Mon Dec 01, 2003 2:23 am
by Nay
First off, I wouldn't know why you would move the config.php. Usually, the config file stays where it always has been.
Second off, here's what you normally do:
Config.php:
Code: Select all
<?php
$path = "e:/www/ibs/cms/includes";
// other stuff
?>
Anotherfile.php
Code: Select all
<?php
include "../../ibs/cms/includes/config.php";
// to include other files
include $path . "otherfile.php";
?>
You'll have to include the config.php file first though, another option is store the path in a MySQL database or so.
-Nay
Posted: Mon Dec 01, 2003 3:33 am
by Pyrite
OK. I setup a simular test setup on my other Linux server that uses Apache/php as well.
I created a config.php which defines a variable to "hey man" and put it in /test/cms/includes/config.php
Then created /test/cms/one/two/three/test.php
And it has:
include('../../../cms/includes/config.php');
And it works!
So what is different about my Windows Server 2003 Apache/Php setup? I don't know. Using MySQL for a path is not an option, and neither is using include file paths like e:\path\to\the\web\root\includes\config.php
On my Server 2003 box, I have the include_path in php.ini commented out. For some reason, Php doesn't like me including files that are not under /cms where all my other php scripts are.
May be someone else might have had a simular experience. ?
Posted: Mon Dec 01, 2003 4:35 am
by Pyrite
Ok, I got it working as I like. I don't really understand it, but it works. And my programming teacher always said, if it works then its right.
Code: Select all
I used this include statement:
include('cms/includes/config.php');
and this include_path in my php.ini
include_path = ".;e:\www\ibs;e:\www\ibs\cms"
Thx for everyone's help.