Is there a way to convert a web URL in to the absolute file system path (independent from OS)?
For example: I have an URL /images/test.jpg
(http://www.example.com/images/test.jpg
) and I need to get:
- `c:\path\to\webroot\images\test.jpg`` on Windows,
/var/path/to/webroot/images/test.jpg
on Linux.
Any way to do this in PHP?
It sounds like you want the realpath function.
This will give you
/images/test.jpg
:Where
$_SERVER['DOCUMENT_ROOT']
gives you the document root directory under which the current script is executing.