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

发布于 2024-12-12 03:15:48 字数 229 浏览 5 评论 0原文

我试图包含另一个目录中的文件,然后将 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

黑白记忆 2024-12-19 03:15:48

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

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

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

First you need to store the current path, before changing dirs:

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

Why do you need to change dirs in order to include a file?

何处潇湘 2024-12-19 03:15:48

在您 <代码>chdir。然后chdir返回。

Save the current directory (getcwd) before you chdir. Then chdir back.

青春有你 2024-12-19 03:15:48

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

You can do this way - chdir('../');
But really not sure in correct behavior

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文