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:
/var/path/to/webroot/images/test.jpg
on Linux.Any way to do this 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']
gives you the document root directory under which the current script is executing.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With