Click to See Complete Forum and Search --> : root of site


jrthor2
12-17-2007, 07:45 PM
Not sure if this is really belongs under the PHP section, but here is my issue. I just signed up with a new host. When I have the below code for an image, the image shows up fine:

<img src="/images/LSS_Seal.png" alt="ELCA" width="49" height="50" />

If I do this, the image does not show up:


<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css">
.main {clear:both; width:900px; padding-bottom:30px; background:transparent url("../images/bg_main_withnav_blue.jpg") top left repeat-y; position:relative; }
</style>
</head>

<body>
<div class="main">

</div>
<!--<img src="/images/LSS_Seal.png" alt="ELCA" width="49" height="50" />-->
</body>

Also, when I do this:
echo $_SERVER['DOCUMENT_ROOT'];
It shows the root as /usr/local/apache/htdocs. This doesn't seem right to me. Any suggestions?

scragar
12-17-2007, 08:06 PM
<!--<img src="/images/LSS_Seal.png" alt="ELCA" width="49" height="50" />-->
that's commented out, ofcourse it doesn't show.

and yeah, $_SERVER['DOCUMENT_ROOT']; shows you the path from the root of the server, you'll find they often have others like that.

jrthor2
12-17-2007, 08:15 PM
I know it's commented out, it's supposed to be. That syntax works, but the syntax using the css does not displau the image.

also, if you'recorect about the document root, how are you suppossed to use

include_once $_SERVER['DOCUMENT_ROOT']

to include files, as this is the preferred way to include files.

Thanks

NogDog
12-17-2007, 10:48 PM
include_once $_SERVER['DOCUMENT_ROOT'] . '/path/to/includes/file.php';

TheRave
12-18-2007, 03:52 AM
So its meant to be commented out? Why are you complaining that its not showing then? Anything thats commented out won't show.

<body>
<div class="main">

</div>
<!--<img src="/images/LSS_Seal.png" alt="ELCA" width="49" height="50" />-->
</body>
Image doesn't display.


<body>
<div class="main">

</div>
<img src="/images/LSS_Seal.png" alt="ELCA" width="49" height="50" />
</body>
Image does display. Wooo!

TheRave
12-18-2007, 03:56 AM
As for $_SERVER['DOCUMENT_ROOT'], as the others say it will return the location of the root web folder. Files in this folder can be access from the root of a website (e.g. www.example.com/imafile.php).

There's nothing odd about the path you're being returned, its totally correct. Remember that on linux servers the path will be from your usr folder. Whereas windows is likely to start from the drive letter (e.g. C:\)

jrthor2
12-18-2007, 06:05 AM
My issue was that if I used the img tag, the image shows up, but if I use the background url tag using css, the image does not show up.

As for $_SERVER['DOCUMENT_ROOT'], if I use that to include files in my pages, it doesn't work because it is looking for the files in /usr/local/apache/htdocs, but that's not where my pages are, they are in /home/zluthorg/public_html, so I get errors when doing

$_SERVER['DOCUMENT_ROOT']."/path/to/file.php";

saying it can't open the file.

TheRave
12-18-2007, 07:13 AM
Ahh ok, the $_SERVER['DOCUMENT_ROOT'] problem has to do with how you have your apache set up to serve files from outside the apache root.

And we now know the image problem is with the CSS:

Try this
background: url("../images/bg_main_withnav_blue.jpg") top left repeat-y

jrthor2
12-18-2007, 07:32 AM
I've already tried

background: url("../images/bg_main_withnav_blue.jpg") top left repeat-y

and that works, but I can't do that if this is going to be included in multiple directories, that could be 2-3 directories deep. I'd need ../../ or ../../../ for those. That defeats the purpose of doing an include for the css.

As for the apache setup, that would be the hosting company's issse, right? Which, I don't think they'll change since this is a shared server.

TheRave
12-18-2007, 07:47 AM
Ahhh now we're homing in on your exact problem. It always pays to give as much details as possible to start with ^^

Is the images folder in your root folder?

As in the image could be shown with http:www.example.com/images/bg_main_withnav_blue.jpg

If it is you can just use a root relative path:

background: url("/images/bg_main_withnav_blue.jpg") top left repeat-y

It might help you to look up relative, root-relative and absolute paths. There's a nice article here:
http://www.communitymx.com/content/article.cfm?cid=230ad

jrthor2
12-18-2007, 08:13 AM
Yes, the images directory is at the root of my site. If I use /images/image.png, it does not show up. If I put the entire url like http://255.255.255.255/~zluthorg/images/image.png then it shows up.

TheRave
12-18-2007, 08:19 AM
Something at the root of the site is something that is imediately after the domain (whether domain name or IP).

For instance in http://255.255.255.255/~zluthorg/images/image.png the images folder is not in the root. The ~zluthorg is.

So:
background: url("/~zluthorg/images/bg_main_withnav_blue.jpg") top left repeat-y

jrthor2
12-18-2007, 11:54 AM
yes, that does work. So this means that the issue is because I am going to an IP address, and not to the domain name. It's like this because we are transferring our current domain to a different hosting company, but I don't wan the current site down until the new one is ready. Then, when it's ready, I'll have to go through all the pages, and remove /~zluthorg/, right?

TheRave
12-19-2007, 03:46 AM
Its not because you're going to an IP address. The IP address is the domain. The problem is because you have a subfolder (~zluthorg) before everything else.

If when the transfer is complete the subfolder doesn't exist then it will have to be adjusted.

Of course you could grab the information dynamically. I'll let you investigate a method how. Its always good to let people learn for themselves :D

jrthor2
12-19-2007, 06:14 AM
And how would you get it dynamically? I've tried $_SERVER['DOCUMENT_ROOT'], which is wrong.

Thanks