/    Sign up×
Community /Pin to ProfileBookmark

Get Root Folder

How do you get the root folder the php file resides and also get the absolute url.

[url]http://www.yahoo.com/example/file.php[/url]

Can php say the file.php resides in folder “example” and then say the absolute url is the above url?

$folder = ?
$url = ?

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@bokehMay 26.2006 — [code=php]<?php

?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
<title>Untitled</title>
<style type="text/css">
span{
float:left;
width:16em;
font-weight:bold;
}
</style>
</head>
<body>
<p><span>This file is called:</span><?php echo basename($_SERVER['PHP_SELF']) ?></p>
<p><span>It resides in the directory:</span><?php echo str_replace(basename($_SERVER['PHP_SELF']), '', $_SERVER['PHP_SELF']) ?></p>
<p><span>The absolute URL is:</span><?php echo $_SERVER['PHP_SELF'] ?></p>
<p><span>The hostname is:</span><?php echo $_SERVER['HTTP_HOST'] ?></p>
<p><span>Put it all together and we have:</span>http://<?php echo $_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'] ?></p>
</body>
</html>[/code]
×

Success!

Help @phpnstuff spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.5,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...