tags:

views:

162

answers:

3

I need to change the folder that "relative include paths" are based on.

I might currently be "in" this folder: C:\ABC\XYZ\123\ZZZ

And in this case, the path "../../Source/SomeCode.php" would actually be in this folder: C:\ABC\XYZ\Source

And realpath('.') would = 'C:\ABC\XYZ\123\ZZZ';

If however, realpath('.') were "C:\Some\Other\Folder"

Then in this case, the path "../../Source/SomeCode.php" would actually be in this folder: C:\Some\Source

How do I change what folder is represented by '.' in realpath()?

Like this:

echo ('BEFORE = '.realpath('.')); // BEFORE = C:\ABC\XYZ\123\ZZZ
// Some PHP code here...
echo ('AFTER = '.realpath('.')); // AFTER = C:\Some\Other\Folder

How can I change the folder represented by '.', as seen by realpath()?

A: 

Change your current working directory with chdir()

http://us.php.net/chdir

awgy
+1  A: 

The function chdir() does this. For example:

echo ('BEFORE = '.realpath('.')); // BEFORE = C:\ABC\XYZ\123\ZZZ
chdir('C:/Some/Other/Folder');
echo ('AFTER = '.realpath('.')); // AFTER = C:\Some\Other\Folder
Arda Xi
Don't use backslashes. Use forward slashes. It works on *all* operating systems.
wallyk
Well, yes, but C:\ wouldn't, so it doesn't really matter.
Arda Xi
It does matter, since it affects portability. Unless you have an absolute requirement to reference the drive letter, you should use Unix-style paths and let PHP translate them for you. That's why the functionality is there.
awgy
+1  A: 

Use the chdir() function.

wallyk
+1 thanks, I learned something new!
alex