how to use chdir to change to current directory?

前端 未结 3 1125
醉话见心
醉话见心 2020-12-19 09:33

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);         


        
相关标签:
3条回答
  • 2020-12-19 09:43

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

    0 讨论(0)
  • 2020-12-19 09:58

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

    0 讨论(0)
  • 2020-12-19 09:59

    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?

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