Welcome to WebmasterWorld Guest from 54.167.5.15

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Getting back to the root directory

     

nvhack

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

5+ Year Member



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,

supermanjnk

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

10+ Year Member



You should just be able to do "/myimages.jpg" Just a simple "/"

The Contractor

7:01 pm on Nov 11, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



<?php include $_SERVER['DOCUMENT_ROOT'].'/mypage.htm'; ?>

nvhack

9:19 pm on Nov 11, 2008 (gmt 0)

5+ Year Member



Thanks,

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

nvhack

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

5+ Year Member



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.

jatar_k

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

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



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

The Contractor

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

WebmasterWorld Senior Member 10+ Year Member



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

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

nvhack

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

5+ Year Member



Yeah I forgot some HTML basics here.
 

Featured Threads

Hot Threads This Week

Hot Threads This Month