PHP realpath('./models') 返回“”或空?

发布于 2024-10-08 02:45:49 字数 544 浏览 0 评论 0原文

当我尝试时,

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

奢华的一滴泪 2024-10-15 02:45:49

根据您发布的输出,您的目录结构似乎如下所示:

D:\Projects\Tickle
    public
        foo.php
    application
        models

我们位于 foo.php 中。通过使用 realpath('./models'); 您引用了不存在的 D:\Projects\Tickle\public\models

更新
如果您想获取一个文件(相对于当前文件),您应该使用类似以下的内容:

realpath(__DIR__ . '/models');

或者更好(__FILE__ 是您所在的当前文件):

realpath(dirname(__FILE__) . '/models')

使用 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:

D:\Projects\Tickle
    public
        foo.php
    application
        models

We are in foo.php. By using realpath('./models'); you refer to D:\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:

realpath(__DIR__ . '/models');

Or even better (__FILE__ is the current file you are in):

realpath(dirname(__FILE__) . '/models')

Using the Zend Framework, the APPLICATION_PATH constant is defined as realpath(dirname(__FILE__) . '/../application') (in public/index.php).

娇俏 2024-10-15 02:45:49

尝试以下操作,看看是否有机会得到 false

var_dump(realpath('./models'));

如果我没记错的话,您的树结构如下所示,并且上面代码所在的文件是 public , 正确的?在这种情况下,您实际上是在尝试获取 public/models 的真实路径。

public
    somefile.php
application
    models

Try following and see if you get false by any chance:

var_dump(realpath('./models'));

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 of public/models.

public
    somefile.php
application
    models
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文