开发者

Changing Base Path In PHP

I need to change the folder th开发者_JAVA技巧at "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()?


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


Use the chdir() function.


Change your current working directory with chdir()

http://us.php.net/chdir

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜