0

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?

3 Answers 3

0

You can do this with server variables:

echo $_SERVER['DOCUMENT_ROOT'] . $_SERVER['REQUEST_URI'];
Sign up to request clarification or add additional context in comments.

Comments

0

This might be causing because correct url is not being passed to parse_url function. Print the $url value before passing to parse_url function and check if it is printing appropriate value. You might be passing something like this http://http://localhost:7777/http://localhost:7777/somesite/sites/default/files/devel-7.x-1.5.zip in $url because of which when parse_url processes the $url, it returns your original $url.

Hope this helps :)

Comments

0

Try

$path = parse_url($url);
echo str_replace('/', "\\", $_SERVER['DOCUMENT_ROOT'].$path['host'].$path['path']);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.