【问题标题】:how to use chdir to change to current directory?如何使用 chdir 切换到当前目录?
【发布时间】:2011-12-17 01:29:31
【问题描述】:

我正在尝试包含另一个目录中的文件,然后将 chdir 更改回当前/原始形式。

chdir('/some/path');
include(./file.php);
chdir();//How to I change the directory back to the original form?

无论如何要将 chdir 改回 file.php 所在的位置?还是我必须手动完成?

【问题讨论】:

    标签: php chdir


    【解决方案1】:

    首先你需要存储当前路径,然后再更改目录:

    $oldPath = getcwd();
    chdir('/some/path');
    include(./file.php);
    chdir($oldPath);
    

    为什么需要更改目录才能包含文件?

    【讨论】:

      【解决方案2】:

      chdir 之前保存当前目录 (getcwd)。然后chdir回来。

      【讨论】:

        【解决方案3】:

        你可以这样做 - chdir('../'); 但真的不确定行为是否正确

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2012-03-18
          • 1970-01-01
          • 2016-03-17
          • 2015-01-15
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多