php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #17822 Realpath, getcwd not returning true pathname
Submitted: 2002-06-18 18:20 UTC Modified: 2007-02-09 10:23 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: csaba at alum dot mit dot edu Assigned: sfox (profile)
Status: Closed Package: Feature/Change Request
PHP Version: 4.3.0 OS: Windows - all
Private report: No CVE-ID: None
 [2002-06-18 18:20 UTC] csaba at alum dot mit dot edu
realpath and getcwd on Windows systems do not actually report the applicable directory, but rather a string that will !strcasecmp() with the true directory:

I have a directory name, $dir, on my Win2K system (PHP 4.2.0), but it's in all lower case, and I'd like to get the actual pathname including the capitalizations: 

Both realpath() and dirname() only muck around with the $dir string and don't hit the file system. Not only that, but getcwd() returns $dir (sans capitalizations) after I've hopped over to it with chdir($dir)! 

My only solution to this point is to pop up a level and use readdir(...) but this is wasteful, only giving me one level at a time. Isn't there a REAL realpath() for windows? 

Thanks, 
Csaba Gabor


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-02-15 17:38 UTC] csaba at alum dot mit dot edu
I have marked this bug as open because of the demonstration below on my PHP 4.3 build date Dec. 20, 2002; Apache 2.0.43 Filter; Win2K Pro system.

Here is the test:
<html><head><title>getcwd Problem</title></head><body>
<?php
$cwd = getcwd();
chdir (strtolower($cwd));
print "<br>" . getcwd();
print "<br>" . realpath(getcwd());
chdir (strtoupper($cwd));
print "<br>" . getcwd();
print "<br>" . realpath(getcwd());
?>
</body></html>

On my system the first 2 directories show in lower case,
the last two are in caps.
Csaba
 [2004-04-23 00:26 UTC] csaba at alum dot mit dot edu
I have tested this with the latest snapshot 5.0 RC 2 of April 22 on my Win 2K Pro system and it is still a problem.  Here are the outputs that I get (I did an inititial print right after the first cwd() so you can see what windows thinks the directory is):

C:\Morph\phpDev\40gNiKU5LQ0C
c:\Morph\phpDev\40gniku5lq0c
c:\Morph\phpDev\40gniku5lq0c
C:\Morph\phpDev\40GNIKU5LQ0C
C:\Morph\phpDev\40GNIKU5LQ0C 

So it appears that the middle part is OK but the drive letter and the final directory need some shoring up.

Csaba Gabor
 [2007-02-09 10:23 UTC] csaba at alum dot mit dot edu
Hurrah!  This now appears fixed.
realpath(strtolower(getcwd())) is now the same as
realpath(strtoupper(getcwd())) is now the same as
getcwd()

on my Win XP Pro under
PHP 5.2.1RC4-dev (cli) (built: Jan 25 2007 08:24:12)

Thanks,
Csaba Gabor from Vienna
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat May 04 09:01:32 2024 UTC