php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #35691 Can't change to another drive letter using chdir()
Submitted: 2005-12-15 21:09 UTC Modified: 2008-11-02 12:30 UTC
Votes:18
Avg. Score:4.7 ± 0.7
Reproduced:15 of 15 (100.0%)
Same Version:7 (46.7%)
Same OS:11 (73.3%)
From: ejwaibel at gmail dot com Assigned: pajoye (profile)
Status: Not a bug Package: Directory function related
PHP Version: 5CVS-2005-12-19 (snap) OS: Windows
Private report: No CVE-ID: None
 [2005-12-15 21:09 UTC] ejwaibel at gmail dot com
Description:
------------
The chdir() command works correctly when changing to a given dir in the SAME drive, however, I believe that it should be capable of changing to another drive letter and then directory in that drive letter.  I know that Windows can do that using "cd /D <path>".

Reproduce code:
---------------
$currentDir = getcwd();
echo "currentDir: $currentDir<br/>";
chdir("Q:\\sdadmin") || die(sendMessage("Can't change to '$substDrive\\sdadmin'", true));	
echo getcwd();

Expected result:
----------------
I would have expected to change from "D:\scmtools\oss\" to "Q:\sdadmin".

Actual result:
--------------
The chdir() function returns false and I show an error message.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-12-16 16:41 UTC] erik dot waibel at cubic dot com
I updated my PHP version to the Windows .zip file that you included, but that still did not work.  We are using a Windows NT 5.2 build 3790 machine (it's a Windows NT server).  I actually just checked and it seems like I can change to the "C:" drive, but what I forgot to mention earlier, here is another piece of my code that is used to "subst" the Q: drive for a directory that exists on another drive.

$subst = exec("subst $substDrive M:\\$sessionView", $substOutput);
				$currentDir = getcwd();
				$changeTo = "$substDrive\\sdadmin";
				chdir("$changeTo") || die("Can't change location to: $changeTo.");

The reason I'm doing this is because of our Source Control program "ClearCase" that we use.  Can you let me know if there is another way I should do this?
 [2005-12-19 00:14 UTC] nlopess@php.net
I've also tested with networked drives and it works fine.
can you please test with a simple script like:
<?php

// list the files in this directory
print_r(glob('*.php'));
var_dump(getcwd());

// change to another drive (replace with something existent)
var_dump(chdir('Z:'));
var_dump(getcwd());
print_r(glob('*'));

?>

Please include all error messages printed by PHP.
 [2005-12-19 01:42 UTC] erik dot waibel at cubic dot com
This is what I get when running the code with an existing drive (such as C:)

Files in current directory...
Array ( [0] => TCdetails.php [1] => TCgetdata.php [2] => TCgetversion.php [3] => TCmanual.php [4] => TCpreview.php [5] => TCprocess.php [6] => TCsearch.php [7] => changes.php [8] => checklist.php [9] => details.php [10] => footer.php [11] => getarq.php [12] => getdata.php [13] => help.php [14] => hints.php [15] => import.php [16] => login.php [17] => manual.php [18] => modules.php [19] => password.php [20] => phpinfo.php [21] => process.php [22] => search.php [23] => srnform_windows.php [24] => stscr.php [25] => user.php ) 
string(35) "d:\scmtools\test\ctssrn-enhancement" CWD: 
bool(true) Change dir: 
string(3) "C:\" CWD: 
Files in CWD...
Array ( [0] => AUTOEXEC.BAT [1] => CONFIG.SYS [2] => Documents and Settings [3] => IO.SYS [4] => Inetpub [5] => MSDOS.SYS [6] => NTDETECT.COM [7] => PHP [8] => Perl [9] => Program Files [10] => RECYCLER [11] => System Volume Information [12] => WINDOWS [13] => boot.ini [14] => dsn [15] => dsn.dir [16] => dsn.pag [17] => mvfslogs [18] => ntldr [19] => pagefile.sys [20] => temp.log [21] => wmpub ) 

This is what I get when I change to the drive that is being 'subst':

Files in current directory...
Array ( [0] => TCdetails.php [1] => TCgetdata.php [2] => TCgetversion.php [3] => TCmanual.php [4] => TCpreview.php [5] => TCprocess.php [6] => TCsearch.php [7] => changes.php [8] => checklist.php [9] => details.php [10] => footer.php [11] => getarq.php [12] => getdata.php [13] => help.php [14] => hints.php [15] => import.php [16] => login.php [17] => manual.php [18] => modules.php [19] => password.php [20] => phpinfo.php [21] => process.php [22] => search.php [23] => srnform_windows.php [24] => stscr.php [25] => user.php ) 
string(35) "d:\scmtools\test\ctssrn-enhancement" CWD: 
bool(false) Change dir: 
string(35) "d:\scmtools\test\ctssrn-enhancement" CWD: 
Files in CWD...
Array ( [0] => TCdetails.php [1] => TCgetdata.php [2] => TCgetversion.php [3] => TCmanual.php [4] => TCpreview.php [5] => TCprocess.php [6] => TCsearch.php [7] => cc-get-modules.exe [8] => cc-import.exe [9] => changes.php [10] => checklist.php [11] => details.php [12] => error_log.log [13] => footer.php [14] => getarq.php [15] => getdata.php [16] => help.php [17] => hints.php [18] => import.php [19] => login.php [20] => manual.php [21] => modules.php [22] => password.php [23] => phpinfo.php [24] => process.php [25] => search.php [26] => srnform_windows.php [27] => stscr.php [28] => user.php )
 [2005-12-19 17:41 UTC] nlopess@php.net
So, this is only happening with attached drive on Windows 2003. I can only think of a bug in GetLongPathName(). 

I'll install windows 2003 server somewhere to test.
 [2005-12-20 19:43 UTC] nlopess@php.net
I've installed win 2003 and I can't reproduce the problem.
Please double check your 'subst' command (by entering in my computer and see if the drive is listed there, etc..)
 [2006-01-19 08:56 UTC] jarek at katnik dot pl
I'm using PHP Version 5.1.2 on  MS Windows XP Pro SP2.
Drive 'R:' is mounted by ClearCase.

When I run script listed bellow I get warrning:

Warning: chdir() [function.chdir]: No such file or directory (errno 2) in {scriptName} on line {lineNumber}


<?php
    chdir('R:');
?>
 [2006-01-19 17:00 UTC] nlopess@php.net
OK, so here I go again. bug #36088 states this only happens with Apache (2.0.x) and works in CLI. Previously I had only tested in CLI, so back to testing.
 [2006-01-20 10:18 UTC] jarek at katnik dot pl
It happpens also with Apache 1.3.31.
 [2006-09-26 15:28 UTC] thiagomp at gmail dot com
The problem appeared here with the following configuration:
Windows XP SP2
PHP 5.0.5 (with Apache 1.3.33) and 5.1.6 (with Apache 2.0.59)
 [2006-11-01 15:05 UTC] nlopess@php.net
OK, I was able to reproduce the problem.
I used Apache 2.0 and is_dir() doesn't work with network mapped drives. other drives work and in CLI mode it also works. (it can be because Apache runs as another user, although I haven't looked further into the problem)
 [2006-11-01 15:11 UTC] nlopess@php.net
I reproduce this with both Windows XP and 2003.
 [2007-05-26 03:34 UTC] laifanleuk at net-yan dot com
Same problem here.  Try to open_dir to a SUBST'ed directory failed.  Using XP sp2, Apache 2.2.4 is install by my admin, running as service .  I have no administrator access right. 

Before my admin installed Apache as service, I was using apache as normal user, running in console mode.  It worked perfectly then.
 [2008-06-23 09:34 UTC] nlopess@php.net
I don't have time to investigate this problem further..
 [2008-06-23 09:54 UTC] pajoye@php.net
There is no bug here. The documentation (php, posix or msdn) says that a path is expected. A drive letter is not a path, even not a relative path.

If it is desired to have php's chdir behaves like chDrive on windows (netware too?), it could be possible to do it. As it will make chdir behaviors inconsistent with the system API, it will keep the php code portable (from an API point of view). 

If not, I can add expose chDrive.
 [2008-11-02 12:30 UTC] jani@php.net
See above. Pierre: When you close a bug, CLOSE them.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Oct 04 23:01:28 2024 UTC