Reputation: 698
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?
Upvotes: 10
Views: 15703
Reputation: 10586
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.
Upvotes: 3