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

后端 未结 3 1119
闹比i
闹比i 2020-12-06 00:12

I\'m in the process of transferring my website from one server to another. I have some php scripts that use the is_readable function which uses the current working director

相关标签:
3条回答
  • 2020-12-06 00:33

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

    0 讨论(0)
  • 2020-12-06 00:41

    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__));
    
    0 讨论(0)
  • 2020-12-06 00:43

    chdir(__DIR__);

    or

    chdir(dirname(__FILE__));

    (see chdir and magic constants).

    But that should be by default.

    0 讨论(0)
提交回复
热议问题