Using require_once for up directory not working

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-29 05:00:02

问题


I am using require_once like this

require_once('../mycode.php')

I am developing a wordpress plugin. My plugin folder is yves-slider where I have a file called yves-slider.php and a folder called admin. Inside admin folder I have a file called admin.php. I want to require file yves-slider.php in my admin.php which is located up one level directory. When I try to use

require_once('../yves-slider.php')

it gives me the following error

Warning: require_once(../yves-slider.php): failed to open stream: No such file or directory in C:\xampp\htdocs\wordpress\wp-content\plugins\yves-slider\yves-slider-admin\yves-slider-admin.php on line 4

Fatal error: require_once(): Failed opening required '../yves-slider.php' (include_path='.;C:\xampp\php\PEAR') in C:\xampp\htdocs\wordpress\wp-content\plugins\yves-slider\yves-slider-admin\yves-slider-admin.php on line 4

Am I doing wrong? I am using XAMPP 3.1, I guess that's the best way to do it.


回答1:


You want to make that relative to the current path the file is in:

require_once __DIR__ . '/../yves-slider.php';

What probably is happening is that the current path PHP looks in is not the path you think it is. If you are curious about what it is (the current path) you could do echo getcwd();.



来源:https://stackoverflow.com/questions/14184223/using-require-once-for-up-directory-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!