6

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

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

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

4

3 回答 3

9

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

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

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

于 2011-10-28T06:00:30.837 回答
0

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

于 2011-10-28T06:01:10.580 回答
-1

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

于 2015-03-16T11:45:01.117 回答