homepage Welcome to WebmasterWorld Guest from 54.161.192.130
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Getting back to the root directory
nvhack

5+ Year Member



 
Msg#: 3784287 posted 6:43 pm on Nov 11, 2008 (gmt 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,

 

supermanjnk

10+ Year Member



 
Msg#: 3784287 posted 6:50 pm on Nov 11, 2008 (gmt 0)

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

The Contractor

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 3784287 posted 7:01 pm on Nov 11, 2008 (gmt 0)

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

nvhack

5+ Year Member



 
Msg#: 3784287 posted 9:19 pm on Nov 11, 2008 (gmt 0)

Thanks,

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

nvhack

5+ Year Member



 
Msg#: 3784287 posted 10:59 pm on Nov 11, 2008 (gmt 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.

jatar_k

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



 
Msg#: 3784287 posted 1:05 am on Nov 12, 2008 (gmt 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

The Contractor

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 3784287 posted 12:21 pm on Nov 12, 2008 (gmt 0)

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

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

nvhack

5+ Year Member



 
Msg#: 3784287 posted 5:01 pm on Nov 12, 2008 (gmt 0)

Yeah I forgot some HTML basics here.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved