Using getcwd() and avoiding the possible outputs you don't want.

If your PHP cli binary is built as a cgi binary (check with php_sapi_name), the cwd functions differently than you might expect.

say you have a script /usr/local/bin/purge you are in /home/username

php CLI: getcwd() gives you /home/username php CGI: getcwd() gives you /usr/local/bin

This can trip you up if you're writing command line scripts with php. You can override the CGI behavior by adding -C to the php call (or shebang):

#!/usr/local/bin/php -Cq

and then getcwd() behaves as it does in the CLI-compiled version.

http://us3.php.net/getcwd »

Page Comments (Click to edit)






[Click to add or edit comments])

Please prepend comments below including a date

Design by N.Design Studio, adapted by solidGone.org (version 1.0.0)
Have a nice day.