如何使用 chdir 更改到当前目录?
我试图包含另一个目录中的文件,然后将 chdir 更改回当前/原始形式。
chdir('/some/path');
include(./file.php);
chdir();//How to I change the directory back to the original form?
无论如何,将 chdir 更改回 file.php 所在的位置?或者我必须手动完成?
I'm trying to include a file from another directory and then change the chdir back to the current/original form.
chdir('/some/path');
include(./file.php);
chdir();//How to I change the directory back to the original form?
Anyway to change the chdir back to where file.php is located? or do I have to do it manually?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
首先,在更改目录之前,您需要存储当前路径:
为什么需要更改目录才能包含文件?
First you need to store the current path, before changing dirs:
Why do you need to change dirs in order to include a file?
在您 <代码>chdir。然后
chdir
返回。Save the current directory (
getcwd
) before youchdir
. Thenchdir
back.你可以这样做 - chdir('../');
但真的不确定行为是否正确
You can do this way - chdir('../');
But really not sure in correct behavior