开发者

How can I set an absolute path for include function in php above the working directory?

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

(t开发者_如何学Pythonhe 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


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


Something wrong with:

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

?

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

C.


use this.

require_once(ABSPATH.'forum/chat/index.php');

here ABSPATH = WordPress physical root directory path with trailing slash

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜