PHP: Warning: include failed to open stream no suc

2019-02-22 03:58发布

I have an include statement in a PHP script running on xampp on Windows. If I use a relative path :

include '../config/eventInfoConfig.php';  

I get the error message:

Warning: include(../config/eventInfoConfig.php) [function.include]: failed to open stream: No such file or directory

But if I use the absolute path I have no error:

include 'c:/xampp/htdocs/xampp/appTrials/myApp/config/eventInfoConfig.php'; 

How can I use a relative path in my include without causing an error?

3条回答
姐就是有狂的资本
2楼-- · 2019-02-22 04:35

You can turn the relative path into an absolute one. include is tricky. I always just keep a global constant, BASE_PATH, that contains the absolute path, and append the file I need to include.

查看更多
成全新的幸福
3楼-- · 2019-02-22 04:39

I would make it dynamic so that you can also include this file in other files and still have it work properly.

include_once(dirname(__FILE__).'/../config/eventInfoConfig.php');
查看更多
该账号已被封号
4楼-- · 2019-02-22 04:43

Fixing the include_path() to include the right path does the trick.

查看更多
登录 后发表回答