views:

280

answers:

2

I am running a script from

/wp-content/themes/currenttheme/chat.php

I want to include in the above php another one located in

/forum/chat/index.php

The index.php includes its own files

I already tried

$root = $_SERVER['DOCUMENT_ROOT'];
include($root."/forum/chat/index.php");

but I get this error

Warning: require(D:/My Dropbox/xampp/htdocs/lib/custom.php) [function.require]: failed to open stream: No such file or directory in D:\My Dropbox\xampp\htdocs\forum\chat\index.php on line 17

Fatal error: require() [function.require]: Failed opening required 'D:/My Dropbox/xampp/htdocs/lib/custom.php' (include_path='.;\My Dropbox\xampp\php\PEAR') in D:\My Dropbox\xampp\htdocs\forum\chat\index.php on line 17

(the index.php also includes some files, but the /forum/chat is ommited somehow in the path)

then I tried

$path   = getcwd();
$myfile = "/forum/chat/index.php";
include ($path.$myfile);

and got this error:

Warning: include(D:\My Dropbox\xampp\htdocs\forum/forum/chat/index.php) [function.include]: failed to open stream: No such file or directory in D:\My Dropbox\xampp\htdocs\wp-content\themes\currenttheme\chat.php on line 24

Warning: include() [function.include]: Failed opening 'D:\My Dropbox\xampp\htdocs\forum/forum/chat/index.php' for inclusion (include_path='.;\My Dropbox\xampp\php\PEAR') in D:\My Dropbox\xampp\htdocs\wp-content\themes\currenttheme\chat.php on line 24

A: 

There is no problem with index.php. It is being included. The error message says about custom.php file

Just use the same $_SERVER['DOCUMENT_ROOT'] technique for the custom.php

you have to add /forum/chat manually as there is no path to be omitted

Col. Shrapnel
custom.php is included in index.php and it works fine when launched any way except when I try to do the above mentioned inclusion
Baros
@Baros So what? Why not to repair it the way I told you?
Col. Shrapnel
A: 

Something wrong with:

include('../../../forum/chat/index.php');

?

There are all sorts of reasons why the code you've published will fail.

C.

symcbean
When I use it as you wrote it, I get the second error. It starts working only if I add another / before the first .. but now I get the first error.
Baros
using relative path is always bad idea.
Col. Shrapnel
I agree. But I have no choice 'Warning: include() [function.include]: http:// wrapper is disabled in the server configuration by allow_url_include=0' and 'Warning: include() [function.include]: URL file-access is disabled in the server configuration'
Baros
@Col. Shrapnel - There's no such thing as 'always' when it comes to questions of programming style - although I admit that **usually** using relative paths other than '.' are a bad idea.
symcbean