I'm trying to write a script to browse and return similar to working in the terminal.
Most commands work fine, however cd /path/to/files
just doesn't do anything.
What about PHP chdir?
http://php.net/manual/en/function.chdir.php
Or use backticks?
`cd /path/to/files`
Each command to shell_exec
runs in its own shell. Thus, if you do a cd
, that will only affect that command.
If you want to change directory, use chdir
.
You're looking for chdir
. It is a PHP function.
shel_exec('cd /some/where');
actually works just fine (it changes the current shell_exec
to a different directory), but it will not hold on to the current directory after the shell_exec
finishes. This means that the next command won't share the same state that would have been altered by the call to cd
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With