Reputation:
Sorry I moved from PHP CodeIgniter to Pure PHP; I dont know how I can get the base url;
This is what I have attempted:
echo($_SERVER['SERVER_NAME'].":".$_SERVER['SERVER_PORT'].$_SERVER['REQUEST_URI'] .'../template.jpg');
the out put is:
localhost:8080/my_scheduler/shedule.php../template.jpg
What I need is the following:
localhost:8080/my_scheduler/template.jpg
the following code:
$_SERVER['SERVER_NAME'].":".$_SERVER['SERVER_PORT'].$_SERVER['REQUEST_URI']
gives me the url for current PHP Script I want to go back and get the reqalpath(); but realpath did not work either!
the following code dies not echo anything!
echo realpath($_SERVER['SERVER_NAME'].":".$_SERVER['SERVER_PORT'].$_SERVER['REQUEST_URI'] .'../template.jpg');
Please let me know if you need more clarification!
Thanks
Upvotes: 0
Views: 1294
Reputation: 1658
my idea dispatch your adress with the parse_url command . then start and make your true adders with order you like
official example:
<?php
$url = 'http://username:password@hostname/path?arg=value#anchor';
print_r(parse_url($url));
echo parse_url($url, PHP_URL_PATH);
?>
Array
(
[scheme] => http
[host] => hostname
[user] => username
[pass] => password
[path] => /path
[query] => arg=value
[fragment] => anchor
)
Upvotes: 1
Reputation: 449803
realpath()
works for valid filesystem paths only. There is no ready-made function for this, you'd have to manually cut away the last directory.
If this is for the browser, you could just use a relative URL, though:
<img src="../template.jpg">
Upvotes: 0