/    Sign up×
Community /Pin to ProfileBookmark

Trouble with paths

Hi I know this has been posted before but for some reason I cant figure why mine isn’t working. I’ve looked at other problems on this forum, but they dont help.

I have checked the phpinfo and I can use the DOCUMENT_ROOT, which I’m storing in $webroot:

$webroot = $_SERVER[‘DOCUMENT_ROOT’] .”/”;

which gives:

/aber/www/users

Which I have checked in the phpinfo file, which matches it.

in unix, the structure is /aber/<myusername>/ this is shown when i type ~ tidle key.

so my path is /aber/<myusername/public_html/<mydirectory>/

Right?

This doesnt work so I have just put the absolute path in the http://users.aber.ac.uk/<myusername>/<mydirectoy>/ the page does not display any errors, but I cant seem to include the include pages, which are needed as they have the html body, head tags in them, therfore my styles aren’t showing up.

Has anyone got any Ideas, thank you in advance.

to post a comment
PHP

15 Comments(s)

Copy linkTweet thisAlerts:
@LiLcRaZyFuZzYNov 18.2005 — What is your include path, check that in phpinfo > PHP core > include_path
Copy linkTweet thisAlerts:
@rincewind456Nov 18.2005 — Why not put the files in a folder within the www folder, I usually put all my includes in a folder called "library" and then call them with [code=php]include('library/filename.php');[/code]
Copy linkTweet thisAlerts:
@ScleppelNov 18.2005 — I'm not sure if i have this right, but if you just want to work out "/aber/<myusername/public_html/", you could use this:
[code=php]$web_root = str_replace(dirname($_SERVER['PHP_SELF']),'',dirname(__FILE__)) . '/';[/code]
BUT it fails when you have a URL such as http://example.tld/dir/page.php/something/

another way could be
[code=php]$web_root_array = explode('/',dirname(__FILE__));
$web_root = '/';
$deep = 3; // /aber/<myusername/public_html/ is 3
for($i=1;$i<$deep+1;++$i)
{
$web_root .= $web_root_array[$i] . '/';
}[/code]

but with that you have to say how many directories deep web root is.

Edit: Removed the 2s from the second examples variables.
Copy linkTweet thisAlerts:
@solidaritiauthorNov 18.2005 — What is this __FILE__?
Copy linkTweet thisAlerts:
@solidaritiauthorNov 18.2005 — I have the includes in a folder called includes, include('includes/filename.php'); but it still doesnt work
Copy linkTweet thisAlerts:
@ScleppelNov 18.2005 — __FILE__ is The full path and filename of the file. If used inside an include, the name of the included file is returned. Since PHP 4.0.2, __FILE__ always contains an absolute path whereas in older versions it contained relative path under some circumstances.[/QUOTE]

EDIT:

Does putting [code=php]error_reporting(E_ALL);[/code] at the top of your script make it output any errors?
Copy linkTweet thisAlerts:
@rincewind456Nov 18.2005 — I have the includes in a folder called includes, include('includes/filename.php'); but it still doesnt work[/QUOTE]

Is the "includes" folder in the same directory as the file calling it?

ie: both in the www directory.
Copy linkTweet thisAlerts:
@solidaritiauthorNov 18.2005 — Yes they are both in the top directory:

so

$webroot = $_SERVER['DOCUMENT_ROOT'] ."/";

which gives: /aber/www/users/

but it cant find the include files under public_html, if that makes sense

public_html/

css/

includes/

player-profiles/

etc...
Copy linkTweet thisAlerts:
@SpectreReturnsNov 18.2005 — I suspect that your webroot is set to the www/ folder, and thus that is as far back as PHP will go from the / prefixed path.
Copy linkTweet thisAlerts:
@solidaritiauthorNov 18.2005 — I suspect that your webroot is set to the www/ folder, and thus that is as far back as PHP will go from the / prefixed path.[/QUOTE]

is there any other way to do this then?
Copy linkTweet thisAlerts:
@SpectreReturnsNov 19.2005 — Remove the first two directories, and then use that as a path. You could do this by the following:
[code=php]
$path = "/aber/www/users/";

$temp = explode("/", $path);
unset($path[1], $path[2]); // not sure if you can use unset like this, if not break into several statements

$path = implode("/", $temp);
[/code]
Copy linkTweet thisAlerts:
@solidaritiauthorNov 19.2005 — So that will set the path to www/user then? The thing is is my university server, and I dont have root access, will this matter?
Copy linkTweet thisAlerts:
@bokehNov 19.2005 — The whole point of using $_SERVER['DOCUMENT_ROOT'] is you don't need to know the path; only the path from root. It is then of no relevance where the file calling the include is located. In your case if the directory [I]includes [/I]is in the root directory you would call the include like this:[code=php]include($_SERVER['DOCUMENT_ROOT'].'/includes/filename.php');[/code]If that doesn't work you need to check permissions and that there is no capitalization in your filename/path.

Another mistake you are making (in my opinion) is having your includes in a publically accessible directory.
Copy linkTweet thisAlerts:
@solidaritiauthorNov 19.2005 — How would I make it not accessible then? I'm confused but dont I want these to be accessible as they form part of my pages.
Copy linkTweet thisAlerts:
@bokehNov 19.2005 — If your server path was like this:

/server/websites/[I][B]user[/B][/I]/root/sub/

you would put your includes directory in [I][B]user[/B][/I] where it is not publicly readable. When you want to include a file do this:[code=php]include($_SERVER['DOCUMENT_ROOT'].'/../includes/filename.php'); [/code]
×

Success!

Help @solidariti 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.18,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

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