PHP: How to set current working directory to be same as directory executing the script

狂风中的少年 提交于 2019-11-27 22:48:39

chdir(__DIR__);

or

chdir(dirname(__FILE__));

(see chdir and magic constants).

But that should be by default.

This is normal in CLI mode:

It does not change the working directory to that of the script. (-C and --no-chdir switches kept for compatibility)

a quick workaround would be

chdir(dirname(__FILE__));

You can get the current directory a script is in with dirname(__FILE__) or __DIR__ if >= PHP 5.3.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!