Changing the base path in PHP

I need to change the folder on which "relative included paths" are based.

Currently I can be in this folder: C: \ ABC \ XYZ \ 123 \ ZZZ

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

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

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

Then in this case the path "../../Source/SomeCode.php" will really be in this folder: C: \ Some \ Source

How to change which folder is represented by the '.' 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 ()?

+3
source share
3 answers

chdir() . :

echo ('BEFORE = '.realpath('.')); // BEFORE = C:\ABC\XYZ\123\ZZZ
chdir('C:/Some/Other/Folder');
echo ('AFTER = '.realpath('.')); // AFTER = C:\Some\Other\Folder
+4
+1
0

Source: https://habr.com/ru/post/1742377/


All Articles