命令行接口-我如何才能获得一个php脚本的目录';s在CLI中运行


command line interface - How can I get the dir of a php script that's running in CLI?

我有一个CLI PHP脚本,我需要知道它当前运行在哪个目录中。由于一些操作,包括getcwd(),目录发生了一些变化。

我该怎么做?

您可以使用__DIR__预定义的常量。

也许您想要:dirname(__FILE__)

http://php.net/manual/en/language.constants.predefined.php