为什么 getcwd() 返回与本地密码不同的目录?

发布于 2024-07-04 00:20:31 字数 492 浏览 3 评论 0原文

我正在 Ubuntu 服务器上做一些 PHP 的事情。

我正在工作的路径是 /mnt/dev-windows-data/Staging/mbiek/test_list 但 PHP 调用 getcwd() 返回 /mnt /dev-windows/Staging/mbiek/test_list(注意它是 dev-windows 而不是 dev-windows-data)。

任何地方都没有任何符号链接。

是否还有其他原因导致 getcwd() 从本地 pwd 调用返回不同的路径?

编辑

我想通了。 PHP 中的 DOCUMENT_ROOT 设置为 /mnt/dev-windows ,这会导致一切崩溃。

I'm doing some PHP stuff on an Ubuntu server.

The path I'm working in is /mnt/dev-windows-data/Staging/mbiek/test_list but the PHP call getcwd() is returning /mnt/dev-windows/Staging/mbiek/test_list (notice how it's dev-windows instead of dev-windows-data).

There aren't any symbolic links anywhere.

Are there any other causes for getcwd() returning a different path from a local pwd call?

Edit

I figured it out. The DOCUMENT_ROOT in PHP is set to /mnt/dev-windows which throws everything off.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(4

烂人 2024-07-11 00:20:31

@Mark

嗯,这太奇怪了! 你的 include_path 是什么 - 这可能会弄乱事情。 我个人已经放弃了它,转而使用内容,因为它太喜怒无常(或者我从来没有学会如何公正地对待它)。

@Mark

Well that's just plain weird! What's your include_path - that could be messing thigns around. I've personally ditched it in favour of contants as it's just so temperamental (or I've never learned how to do it justice).

温馨耳语 2024-07-11 00:20:31

@Ross

我想它出来并用解决方案更新了OP。

@Ross

I figured it out and updated the OP with the solution.

送君千里 2024-07-11 00:20:31

@Ross

我想getcwd() 返回文件系统路径而不是相对 url 路径。

无论哪种方式,事实仍然是路径 /mnt/dev-windows 不存在,而 /mnt/dev-windows-data 却存在。

@Ross

I thought that getcwd() was returning a filesystem path rather than a relative url path.

Either way, the fact remains that the path /mnt/dev-windows doesn't exist while /mnt/dev-windows-data does.

时间你老了 2024-07-11 00:20:31

您在哪个文件中调用 getcwd(),该文件是否包含在您正在运行的文件中(例如运行index.php,包括包含gwtcwd() 的startup.php)。

您正在运行的文件是 /dev-windows/ 还是 /dev-windows-data/? 它适用于您实际运行的文件。


这是我当前项目的示例:

index.php

<?php
    require_once('./includes/construct.php');
    //snip
?>

includes/construct.php

<?php
    //snip
    (!defined('DIR')) ? define('DIR', getcwd()) : NULL;

    require_once(DIR . '/includes/functions.php');
    //snip
?>

Which file are you calling the getcwd() in and is that file is included into the one you are running (e.g. running index.php, including startup.php which contains gwtcwd()).

Is the file you are running in /dev-windows/ or /dev-windows-data/? It works on the file you are actually running.


Here's an example of my current project:

index.php

<?php
    require_once('./includes/construct.php');
    //snip
?>

includes/construct.php

<?php
    //snip
    (!defined('DIR')) ? define('DIR', getcwd()) : NULL;

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