PHP realpath('./models') 返回“”或空?
当我尝试时,
realpath('./')
我得到“D:\Projects\Tickle\public”,
但是当我尝试时,
realpath('./models'); // or './models/'
我得到“”或 null。这是为什么?奇怪的是,当我尝试时,
realpath('../application/models');
我得到了“D:\Projects\Tickle\application\models”,这是正确的
UPDATE
我的目录结构如下所示(我正在使用 Zend Framework)
/application
/models
/controllers
/views
/configs
bootstrap.php <-- this is where I am
When I try
realpath('./')
I get "D:\Projects\Tickle\public"
But when I try
realpath('./models'); // or './models/'
I get "" or null. why is that? The strange thing is that when I try
realpath('../application/models');
I get "D:\Projects\Tickle\application\models" which is right
UPDATE
My directory structure looks like below (I am using Zend Framework)
/application
/models
/controllers
/views
/configs
bootstrap.php <-- this is where I am
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
根据您发布的输出,您的目录结构似乎如下所示:
我们位于
foo.php
中。通过使用realpath('./models');
您引用了不存在的D:\Projects\Tickle\public\models
。更新
如果您想获取一个文件(相对于当前文件),您应该使用类似以下的内容:
或者更好(
__FILE__
是您所在的当前文件):使用 Zend Framework,< code>APPLICATION_PATH 常量定义为
realpath(dirname(__FILE__) . '/../application')
(在public/index.php
中)。According to the output you posted, your directory structure seems to look like this:
We are in
foo.php
. By usingrealpath('./models');
you refer toD:\Projects\Tickle\public\models
which does not exist.UPDATE
If you want to get a file (relative to the current file), you should use something like this:
Or even better (
__FILE__
is the current file you are in):Using the Zend Framework, the
APPLICATION_PATH
constant is defined asrealpath(dirname(__FILE__) . '/../application')
(inpublic/index.php
).尝试以下操作,看看是否有机会得到
false
:如果我没记错的话,您的树结构如下所示,并且上面代码所在的文件是
public
, 正确的?在这种情况下,您实际上是在尝试获取public/models
的真实路径。Try following and see if you get
false
by any chance:If I'm not mistaken, your tree structure is as shown bellow and the file you have above code in is
public
, correct? In that case, you are actually trying to get a real path ofpublic/models
.