Make sure to lowercase the result before comparing Windows paths, because this function returns ambiguous results on Windows. From within Apache, the returned path is lowercase, while from the command line interface (CLI) the returned path uses the 'real' Windows pathname. For example, running the 'print getcwd();' command from 'C:\Program Files' returns either
c:\program files (Apache)
C:\Program Files (CLI)
When the directory is specified using chdir(), getcwd() uses the exact chdir argument. For example:
<?php chdir('C:\\PrOgRaM fIlEs'); print getcwd(); ?>
outputs:
C:\PrOgRaM fIlEs (Apache & CLI)
The following code can be used to return a unambiguous lowercased cwd when running on Windows:
<?php $sCwd = (substr(PHP_OS, 0, 3) == 'WIN') ? strtolower(getcwd()) : getcwd(); ?>