开发者

require_once path can't locate file?

Here is my folder structure as example:

source files/
    controller/
        ctrl_showData.php
    model/
        Database.class.php

Suppose it's now in controller directory, and in the ctrl_showData.php, I want to require the Database.class.php, so I try:

require_once(dirname(__FILE__) .'/../model/Database.class.php');

But when I debug, the program stalls when it execute the statement above, which I guess it can't locate the file. I already read similar questions and tried their solutions, but none work. Any one could help? Thanks! Here is the echo result:

开发者_开发知识库
/controller/../model/Database.class.php

Apparently, it doesn't go the parent directory, which is the source files/, then go to the model/ , but don't know why?

Thanks for the error message suggestions, the error message is:

Warning: require_once(config/config.php): failed to open stream: No such file or directory in /model/Database.class.php

Because I also require the the config.php in the database file, which the path is not correct. I didn't think about that, thank you for all your help!


Try this:

require_once(realpath(dirname(__FILE__) . '/..') . '/model/Database.class.php');


You could try using:

include('./model/Database.class.php')


You can use a relative path, so using this (below) should just be working:

require_once('../model/Database.class.php');


Try wrapping that call in realpath() http://us.php.net/manual/en/function.realpath.php

If your path isn't resolving correctly it will return null, and it cleans up the relative path mess you have in the middle.


What is the error in your error log? Do you get something that says the file can't be found? Do you get an error at all?

Use:

error_reporting E_ALL
ini_set('display_errors', 1);

And then see what is the error. If your error is really about including a missing file, check that the path is right, also check that your include path is right. You could by error have removed the "." in the include_path directive or your CMS could have done so if it wants to restrict you to using their autoloader.

Another idea is to EXIT('BLA') in your file and call your page again to see if the BLA appears, if it does, it means your file is included but there is bug in it and thats why you stall.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜