如何使用chdir切换到当前目录? [英] how to use chdir to change to current directory?

查看:160
本文介绍了如何使用chdir切换到当前目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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?

是否将chdir更改回file.php所在的位置?还是我必须手动进行?

Anyway to change the chdir back to where file.php is located? or do I have to do it manually?

推荐答案

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

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?

这篇关于如何使用chdir切换到当前目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆