note 37715 deleted from function.getcwd by googleguy
| From: | googleguy@php.net | Date: | Tue, 22 Oct 2013 06:51:44 +0000 |
| Subject: | note 37715 deleted from function.getcwd by googleguy | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-196678@lists.php.net to get a copy of this message | ||
Note Submitter: fvu at wanadoo dot nl
----
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();
?>