Is there a way to convert web URLs to an absolute path to the file system (regardless of OS)?
For example: I have a URL /images/test.jpg ( http://www.example.com/images/test.jpg ) and I need to get:
/images/test.jpg
http://www.example.com/images/test.jpg
/var/path/to/webroot/images/test.jpg
How to do it in PHP?
$str = "/images/test.jpg"; $str = realpath("." . $str);
This will give you /images/test.jpg :
$path = str_replace($_SERVER['DOCUMENT_ROOT'], '', $path)
Where $_SERVER['DOCUMENT_ROOT'] provides the root directory of the document in which the current script is running.
$_SERVER['DOCUMENT_ROOT']
Looks like you want a realpath .