Unable to "cd" with PHP shell_exec ()

I am trying to write a script to view and return, similar to working in a terminal.

Most commands work fine, but cd /path/to/files just doesn't do anything.

+4
source share
3 answers

Each shell_exec command runs in its own shell. Thus, if you execute cd , this will only affect this command.

If you want to change the directory, use chdir .

+7
source

You are looking for chdir . This is a PHP function.

shel_exec('cd /some/where'); It works just fine (it changes the current shell_exec to another directory), but it will not be held in the current directory after shell_exec completes. This means that the following command will not use the same state that would be changed by calling cd .

+2
source

What about PHP chdir?

http://php.net/manual/en/function.chdir.php

Or use backlinks?

 `cd /path/to/files` 
+1
source

Source: https://habr.com/ru/post/1435385/


All Articles