I have this URL on localhost: http://localhost:7777/somesite/sites/default/files/devel-7.x-1.5.zip
and want to get c:\xampp\htdocs\somesites\default\files\devel-7.x-1.5.zip
.
As mentioned on this question PHP: Get absolute path from absolute URL:
$path = parse_url($url, PHP_URL_PATH);
echo $_SERVER['DOCUMENT_ROOT'] . $path;
The above snippet should let me get the actual path of the file. Unfortunately this is not working. When printing $path
it returns the $url
instead of somesites\default\files
. Could this be because I'm running it on localhost:7777
?