我正在尝试包含另一个目录中的文件,然后将 chdir 更改回当前/原始形式。
chdir('/some/path');
include(./file.php);
chdir();//How to I change the directory back to the original form?
无论如何要将 chdir 更改回 file.php 所在的位置?还是我必须手动完成?
首先,您需要在更改目录之前存储当前路径:
$oldPath = getcwd();
chdir('/some/path');
include(./file.php);
chdir($oldPath);
为什么需要更改目录才能包含文件?
将当前目录 ( getcwd
) 保存在您之前chdir
。然后chdir
回来。
你可以这样做 - chdir('../'); 但真的不确定行为是否正确