Reputation: 9
I have a PHP program that uses dom->save() with an absolute path.
Applications/XAMPP/xamppfiles/htdocs/feed/ultrafeed.xml
I will be using this on both Mac and Windows machines so is there a way to create a path that is either relative or independent of the user's platform?
Upvotes: 0
Views: 1281
Reputation: 2166
$_SERVER ['DOCUMENT_ROOT'] .DIRECTORY_SEPARATOR . 'path' . DIRECTORY_SEPARATOR .'to'.DIRECTORY_SEPARATOR. 'file';`
If you know where it is relative to the current file use __DIR__
instead f $_SERVER
Upvotes: 0
Reputation: 2348
Yes by using realpath()
Try this, for example you have a relative path:
$path = "feed/ultrafeed.xml";
$path = realpath($path);
echo $path;
This will give you C:\real\path\feed\ultrafeed.xml
on Windows
And /real/path/feed/ultrafeed.xml
on Unix.
Upvotes: 4