Welcome to WebmasterWorld Guest from 54.224.86.148

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Getting back to the root directory

     
6:43 pm on Nov 11, 2008 (gmt 0)

New User

5+ Year Member

joined:Sept 26, 2008
posts: 5
votes: 0


Hi all,

Is there a way to get back to the root folder without having to use the full [domain.name.com...] or multiple ../ ?

I want to be able to do something like this so that when I move files in to a new directory it can still find the image or file.

include($webroot.'myfile.php'); or
<img href=<? echo $webroot ?>'myimage.jpg'>

This must be a simple answer but I'm stuck.

Thanks,

6:50 pm on Nov 11, 2008 (gmt 0)

Full Member

10+ Year Member

joined:July 5, 2004
posts:303
votes: 0


You should just be able to do "/myimages.jpg" Just a simple "/"
7:01 pm on Nov 11, 2008 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Mar 29, 2002
posts:1954
votes: 0


<?php include $_SERVER['DOCUMENT_ROOT'].'/mypage.htm'; ?>
9:19 pm on Nov 11, 2008 (gmt 0)

New User

5+ Year Member

joined:Sept 26, 2008
posts:5
votes: 0


Thanks,

I'll give that a try. Had some issues with something similar.

10:59 pm on Nov 11, 2008 (gmt 0)

New User

5+ Year Member

joined:Sept 26, 2008
posts: 5
votes: 0


Posting back, maybe this will help someone else.

It seems that part of my confusion is that there isn't one solution for specifying the root path for both HTML paths and PHP paths. At least I can't make one work.

For HTML:
A preceding slash '/' does get you to the root for image paths for HTML.

I must have forgotten that gem.
This however does not seem to work for PHP paths for use with INCLUDE statements.

For PHP:
$_SERVER['DOCUMENT_ROOT'] does work for includes.

However, in my particular instance it does so only on my local server. I am running my site on the Mosso Hosting cloud and $_SERVER['DOCUMENT_ROOT'] does not produce the correct server path, so I have to specify it manually.

$_SERVER['DOCUMENT_ROOT'] does not work for me if echo'd as part of the image tag HREF path.

C.

1:05 am on Nov 12, 2008 (gmt 0)

Administrator

WebmasterWorld Administrator jatar_k is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:July 24, 2001
posts:15756
votes: 0


you're confusing the two things

>> for me if echo'd as part of the image tag HREF path.

and it shouldn't, this is a filesystem path, from the root of the server, not just your website

>> A preceding slash '/' does get you to the root for image paths for HTML.

again, as designed, a slash in an html tag implies 'start at the root of the site'

so everything is working exactly as it should

12:21 pm on Nov 12, 2008 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Mar 29, 2002
posts:1954
votes: 0


For HTML why not use a base reference in between your <head> </head> tags:

<base href="http://www.yourdomain.com/" >

5:01 pm on Nov 12, 2008 (gmt 0)

New User

5+ Year Member

joined:Sept 26, 2008
posts:5
votes: 0


Yeah I forgot some HTML basics here.