include() problems
Moderator: General Moderators
- Pyrite
- Forum Regular
- Posts: 769
- Joined: Tue Sep 23, 2003 11:07 pm
- Location: The Republic of Texas
- Contact:
include() problems
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.
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.
so you tried
?
Code: Select all
include("../../../../../cms/includes/config.php");- Pyrite
- Forum Regular
- Posts: 769
- Joined: Tue Sep 23, 2003 11:07 pm
- Location: The Republic of Texas
- Contact:
When I try including with the absolute path include("/cms/includes/config.php");
I get this errors..
And when I include with the relative path, I get this:
Really, I'd like to be able to use the absolute path include if I can.
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 2Code: 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 2mMm.......get the path of a file with:
Place, that script where config.php is, then use that path. It should work.
-Nay
Code: Select all
<?php
echo realpath("config.php");
?>-Nay
- Pyrite
- Forum Regular
- Posts: 769
- Joined: Tue Sep 23, 2003 11:07 pm
- Location: The Republic of Texas
- Contact:
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);
?>- Pyrite
- Forum Regular
- Posts: 769
- Joined: Tue Sep 23, 2003 11:07 pm
- Location: The Republic of Texas
- Contact:
Ok, I did that and included the file with:Nay wrote:mMm.......get the path of a file with:
Place, that script where config.php is, then use that path. It should work.Code: Select all
<?php echo realpath("config.php"); ?>
-Nay
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.
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:
Anotherfile.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
Second off, here's what you normally do:
Config.php:
Code: Select all
<?php
$path = "e:/www/ibs/cms/includes";
// other stuff
?>Code: Select all
<?php
include "../../ibs/cms/includes/config.php";
// to include other files
include $path . "otherfile.php";
?>-Nay
- Pyrite
- Forum Regular
- Posts: 769
- Joined: Tue Sep 23, 2003 11:07 pm
- Location: The Republic of Texas
- Contact:
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. ?
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. ?
- Pyrite
- Forum Regular
- Posts: 769
- Joined: Tue Sep 23, 2003 11:07 pm
- Location: The Republic of Texas
- Contact:
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.
Thx for everyone's help.
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"