Re: cd vs. chdir()
| From: | Ernest E Vogelsinger | Date: | Sun, 04 May 2003 22:42:25 +0000 |
| Subject: | Re: cd vs. chdir() | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-146385@lists.php.net to get a copy of this message | ||
At 23:50 04.05.2003, Ron Rudman spoke out and said:
--------------------[snip]--------------------
>>From a php file, is it not possible to change the working directory using a
>
cd, or is it required to use the php function chdir()? Here is
>my test:
>
><?php
>
>echo "test 1\n";
>echo pwd;
>cd /var/log;
>echo pwd;
>
>echo "test 2\n";
>system("pwd");
>system("cd /var/log");
>system("pwd");
>
>echo "test 3\n";
>echo getcwd()."\n";
>chdir("/var/log");
>echo getcwd()."\n";
>system("pwd");
>?>
>
>and here is the output:
>test 1
>/usr/hh/bin
>/usr/hh/bin
>test 2
>/usr/hh/bin
>/usr/hh/bin
>test 3
>/usr/hh/bin
>/var/log
>/var/log
--------------------[snip]--------------------
If you're exec'ing (backticks, system, or any other shell-related
function), PHP spawns a child process. This child process will correctly
change dirs as directed, but the current directory of the parent process -
your PHP script execution - remains unchanged.
The chdir() function is executed by the PHP engine, and changes the working
directory of your PHP process.
--
>O Ernest E. Vogelsinger
(\) ICQ #13394035
^ http://www.vogelsinger.at/