#43977 [Com]: chdir() not working with absolute path / CWD not properly reset

From: Date: Mon, 26 May 2008 08:09:51 +0000
Subject: #43977 [Com]: chdir() not working with absolute path / CWD not properly reset
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-125248@lists.php.net to get a copy of this message
 ID:               43977
 Comment by:       php5 dot 20 dot cheef-daniel at spamgoumet dot com
 Reported By:      sysdev at gmx dot net
 Status:           Open
 Bug Type:         Directory function related
 Operating System: Windows Server 2003
 PHP Version:      5.2.5
 New Comment:

I checked it with php 5.2.5 and 5.2.6 + IIS + Win 2003 Server SP1.
Same error on both versions, I even can't include files because of
this.

include(config.php) [function.include]: failed to open stream: No such
file or directory

config.php is in the same directory and has same rights than the
calling index.php.

getcwd, placed on top of index.php shows me everytime I run this script
another dir out of the docroot. chdir(basename(__FILE__)) under/above
getcwd fails with error 0 like in this bugreport.


Previous Comments:
------------------------------------------------------------------------

[2008-03-29 12:23:10] sysdev at gmx dot net

Seems to be fine for the first chdir-call, but the first getcwd-call
still shows the CWD of the last PHP-script-run before, not the base
directory of the current PHP-script.

------------------------------------------------------------------------

[2008-03-26 12:31:16] jani@php.net

Please try using this CVS snapshot:

  http://snaps.php.net/php5.2-latest.tar.gz
 
For Windows (zip):
 
  http://snaps.php.net/win32/php5.2-win32-latest.zip

For Windows (installer):

  http://snaps.php.net/win32/php5.2-win32-installer-latest.msi



------------------------------------------------------------------------

[2008-01-29 21:49:37] sysdev at gmx dot net

Description:
------------
IIS 6 with PHP 5 SAPI:

In some cases, the CWD of a PHP-script run is not properly reset to the
script's directory. Its instead the directory of another previously run
script.

chdir() with an absulote path fails in these cases if the desired path
is no child of the script's path itself, while chdir() with a relative
path to the same destination succeedes.

Reproduce code:
---------------
Script located in d:\webshare\web3

echo '<div>CWD is '.getcwd().'</div>';
chdir( 'd:\\webshare\\web3' );
echo '<div>CWD is '.getcwd().'</div>';
chdir( 'd:\\webshare\\web3\\test' );
echo '<div>CWD is '.getcwd().'</div>';

Expected result:
----------------
Script located in d:\webshare\web3

CWD is 'd:\webshare\web3'
CWD is 'd:\webshare\web3'
CWD is 'd:\webshare\web3\test'

Actual result:
--------------
Script located in d:\webshare\web3

CWD is 'd:\webshare\another\scripts\path'
Warning: chdir() [function.chdir]: No such file or directory (errno 2)
in D:\webshare\web3\test.php on line 4
CWD is 'd:\webshare\another\scripts\path'
CWD is 'd:\webshare\web3\test'

-- or sometimes --

Script located in d:\webshare\web3

CWD is 'd:\webshare\another\scripts\path'
Warning: chdir() [function.chdir]: No error (errno 0) in
D:\webshare\web3\test.php on line 4
CWD is 'd:\webshare\another\scripts\path'
CWD is 'd:\webshare\web3\test'




------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=43977&edit=1



Thread (8 messages)

« previous php.bugs (#125248) next »