Display absolute location of links

Is it possible in any way to show the location of links absolutely when I only refer to it relatively.

those. File referenced relatively ...

<a href='../../files/uploaded_file.jpg'>Your Uploaded File</a>

But I would also like to display a text saying ...

You can link to your file via www.example.com/files/uploaded_file.jpg

A trick in which I do not want to explain indicates what a domain is, since the script will be used in many different domains without the need to edit the script.

Basically, I want to somehow drop the text that you see in the firefox status bar when you hover over the link.

+5
source share
5 answers

Do a:

var_dump ($ _ SERVER);

, URL- .

+1
<a href="<?php echo 'http://'.$_SERVER['HTTP_HOST'] . '/files/uploaded_file.jpg'; ?>">Your file</a>
+1

, , , , , .

http://www.example.com/one/two/example-page.php

:

<a href='http://<?php echo htmlentities($_SERVER['SERVER_NAME'], ENT_QUOTES)?>/files/uploaded_file.jpg'>Your Uploaded File</a>

, , , .

http: //www.example.com/content/files/uploaded_file.jpg

, URL-.

<?php
$FilesystemPath = str_replace("\\", "/", realpath(dirname(__FILE__) . "/../../files/")) . "/uploaded_file.jpg";
$DocRoot = $_SERVER['DOCUMENT_ROOT'];
$Uri = str_replace($DocRoot, '', $FilesystemPath);
?>
<a href='http://<?php echo htmlentities($_SERVER['SERVER_NAME'] . $Uri, ENT_QUOTES)?>'>Your Uploaded File</a>

, , , .

, URL-. , http, https. , , , .

+1

If the link is relative, you can prefix it with the current host + in PHP. You will need to format the path to resolve the relative parts of the URL, for example /../, a simple loop will do this.

0
source

All Articles