如何使用chdir更改为当前目录?

时间:2011-10-28 05:58:33

标签: php chdir

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

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

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

3 个答案:

答案 0 :(得分:9)

首先,您需要在更改目录之前存储当前路径:

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

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

答案 1 :(得分:0)

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

答案 2 :(得分:-1)

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