开发者

Problem with including a file

i am getting this error

[28-Jan-2011 09:49:03] PHP Warning:  require_once(../../includes/database.php) [<a href='function.require-once'>function.require-once</a>]: failed to open stream: No such file or directory in /Applications/MAMP/htdocs/photo/application/php/classes/users.php on line 2

[28-Jan-2011 09:49:03] PHP Fatal error: require_once() [function.require]: Failed opening required '../../includes/database.php' (include_path='.:/Applications/MAMP/bin/php5.3/lib/php') in /Applications/MAMP/htdocs/photo/application/php/classes/users.php on line 2

The file i would like to include is in

/Applications/MAMP/htdocs/photo/application/includes/database.php

I am sure the file is there, i have checked, double checked, triple checked This is the line 2 in users.ph开发者_Python百科p

require_once '../../includes/database.php';

What could be the problem


Try this at the main file (e.g. index.php)

define('BASEPATH', realpath(dirname(__FILE__)).DIRECTORY_SEPARATOR);

and then

require_once(BASEPATH.'../../includes/database.php');

Working with full paths is always a good idea.

ps: it was an example, the path might be wrong.


The default include path is relative to the calling file (. is the path).

Example dir structure:

index.php
foo.php
bar.php
/assets/foo.php
       /bar.php

if your index.php calls

include 'assets/foo.php';

and one/foo.php calls

include 'bar.php';

it will be equivalent to index.php calling

include 'assets/bar.php';

If you want your includes to all come from the same context, you'll need to use a root-relative path (@yoda has a good example of this).

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜