Basic query

K

KiwiBrian

I want to have a few special files in my root directory and be able to link
to them from anywhere in the lower levels of the site hierarchy.
I am familiar with the ../ method of going up a level in the path but this
implies that I know how deep the calling file is nested.
Is there a method of addressing that will allow me to locate the calling
file anywhere in the hierarchy, and will work regardless of whether the site
is on my hard drive or on a server?
I hope I am being clear.
I hope there is a simple answer.
TIA
Brian Tozer
 
B

brucie

In alt.html KiwiBrian said:
Is there a method of addressing that will allow me to locate the calling
file anywhere in the hierarchy, and will work regardless of whether the site
is on my hard drive or on a server?

href="/directory/myfile.ext"

'/' starts from the root
 
D

Dave Patton

I want to have a few special files in my root directory and be able to
link to them from anywhere in the lower levels of the site hierarchy.

The path "/" is the root, so you would have:
href="/specialK.gif" etc.
Is there a method of addressing that will allow me to locate the
calling file anywhere in the hierarchy, and will work regardless of
whether the site is on my hard drive or on a server?

That's not clear - what exactly do you want?
What do you mean by "locate the calling file"?
 
K

KiwiBrian

In alt.html KiwiBrian said:
href="/directory/myfile.ext"

'/' starts from the root

Thanks for your reply Brucie.
Maybe I worded my enquiry poorly, or maybe I am misunderstanding your reply.
I wish to utilise a background graphic file 'pgbk.jpg' that is in a
subfolder 'hpfiles' of my root directory.
I wish to call/access this from my .CSS files that are in various levels of
the site hierarchy so that all pages are using the same graphic.
I tried to implement what I thought you were telling me as follows:-

background-image: url(/hpfiles/pgbk.jpg);

This did not work as the root directory is several levels higher in the
hierarchy.
I would expect it to only work if the 'hpfiles' directory was a subdirectory
of the calling directory.
I hope you can clarify this for me.

Brian Tozer
 
R

rf

KiwiBrian said:
background-image: url(/hpfiles/pgbk.jpg);
This did not work as the root directory is several levels higher in the
hierarchy.
I would expect it to only work if the 'hpfiles' directory was a subdirectory
of the calling directory.

/ refers to the root.

Even if your CSS file is
example.com/folder/folder/folder/example.css
/hpfiles/pgbk.jpg refers to the file
example.com/hpfiles/pgbk.jpg

What about putting the name in " like the spec suggests?

background-image: url("/hpfiles/pgbk.jpg");
 
K

KiwiBrian

rf said:
/ refers to the root.

Even if your CSS file is
example.com/folder/folder/folder/example.css
/hpfiles/pgbk.jpg refers to the file
example.com/hpfiles/pgbk.jpg

What about putting the name in " like the spec suggests?

background-image: url("/hpfiles/pgbk.jpg");

Just tried that thanks Richard but still didn't work.
I am testing this on my HD.
How does the browser know where my root folder is?
I test by opening the index.html file in the 'root directory' and use the
site menu from there.
When I get to the test page, voila, no background.
Am I missing something very basic?

Brian Tozer
 
N

Neal

Just tried that thanks Richard but still didn't work.
I am testing this on my HD.
How does the browser know where my root folder is?
I test by opening the index.html file in the 'root directory' and use the
site menu from there.
When I get to the test page, voila, no background.
Am I missing something very basic?

Perhaps.

On my OS (W98) the directories are delineated with \. On the web, they are
marked with /.

So, if I try to view a page which references a \ location, it fails.

I suspect that's your trouble.
 
N

Neal

On my OS (W98) the directories are delineated with \. On the web, they
are marked with /.

So, if I try to view a page which references a \ location, it fails.

I suspect that's your trouble.

Worded that poorly.

On my computer, I must go to "directory\file.ext"

On the server, it's "directory/file.ext"

Hope that clears it up.
 
K

KiwiBrian

Neal said:
Perhaps.

On my OS (W98) the directories are delineated with \. On the web, they are
marked with /.

So, if I try to view a page which references a \ location, it fails.

I suspect that's your trouble.

Thanks Neal, but all accessing is being done with the browser. I am using /
extensively within the site and it is only this situation which does not
work.
I have just tried both single and double-quotes around the path and filename
(just within the brackets), but no joy.

Brian Tozer
 
K

KiwiBrian

brucie said:
In alt.html KiwiBrian said:


how long are you going to keep stringing everyone along before you post
a URL demonstrating the problem?

after of course running it through validation

http://validator.w3.org/
http://jigsaw.w3.org/css-validator/

Fair comment Brucie, but unfortunately that is not possible with this site
at the moment.
However I do appreciate the help and it has given me some avenues to pursue.
If necessary I will mock up a simulation of the problem to put online.
I had initilly assumed that the problem was just my lack of knowledge of the
proper method, but you have clarified that.
Thanks again.
The operation was a success, but unfortunately the patient died.

Brian Tozer
 
B

brucie

In alt.html KiwiBrian said:
If necessary I will mock up a simulation of the problem to put online.

thats a good idea
The operation was a success, but unfortunately the patient died.

it should work without an issue so you're doing something wrong
somewhere.
 
D

David Dorward

KiwiBrian said:
I want to have a few special files in my root directory and be able to
link to them from anywhere in the lower levels of the site hierarchy.
I am familiar with the ../ method of going up a level in the path but this
implies that I know how deep the calling file is nested.

As mentioned by others, construct the URI relative to the root of the host
with a '/' at the front of the URI.
Is there a method of addressing that will allow me to locate the calling
file anywhere in the hierarchy, and will work regardless of whether the
site is on my hard drive or on a server?

Using '/' will either work to the root of your filesystem (on UNIX-like
systems) or (I guess) the root of the current drive (on MSDOS-like
systems). Run your own webserver (The industry standard, Apache, is free
for many operating systems <http://httpd.apache.org/>), then access your
local site through that. This will let you have it based around a sensible
site root (and let you test your implementation of any server side
technologies you might wish to use).
 
R

rf

KiwiBrian wrote:
Just tried that thanks Richard but still didn't work.
I am testing this on my HD.

Bloody hell.

Why... did... you... not... state... this... before...?


The "root" folder on your hard disk is, of course, c:\.

Is there a c:\hpfiles\ folder on your hard disk? I'll bet not. It would be
called something like
c:\\web documents\www\root\hpfiles\ wouldn't it.

Of course the browser can't find the file. You have put it elsewhere than
where you told the browser it is.
How does the browser know where my root folder is?

It doesn't. It doesn't care. It tells whatever file system it is accessing
"give me this file", which happens to be /hpdocs/pgbk.gif. For file:// (the
local file system) this resolves to c:\hpdocs\pgbk.gif. For http:// (the
web) it resolves to http://example.com/hpdocs/pgbk.gif which happens to be a
file in a folder that is in the web root.
I test by opening the index.html file in the 'root directory' and use the
site menu from there.
When I get to the test page, voila, no background.
Am I missing something very basic?

Yep. web != local file system.

You have four alternatives:

1) put your entire site in the root folder of your hard disk, that is c:\.
Not a good thing to do.

2) Upload the site to a web host somewhere and test from there. Not really
required.

3) Download and install a web server. Apache comes for free and takes about
5 minutes to install. Good thing to do.

4) Trick the file system into thinking that c:\\web documents\www\root\ *is*
a root. Sneaky but quick and it works.

Do this:
Share the above folder on the network.
Go to My Network Places, navigate to this shared folder and "map network
drive" it to, say, drive z:.

Then c:\web documents\www\root\ can be also referenced as z:\ and z:\is the
root of this "drive" and z:\hpfiles\ is a valid folder and from the browsers
point of view (if you are viewing z:\somefolder\somefile.html) and
url("/hpfiles/pgbk.jpg") resolves (via the file system) to
z:\hpfiles\pgbk.jpg and this exists, even though its real address is c:\web
documents\www\root\hpfiles\pgbk.gif.

OK?
 
B

brucie

In alt.html rf said:
3) Download and install a web server. Apache comes for free and takes about
5 minutes to install. Good thing to do.

OK?

no, i've been doing too much head banging of late. everything inside has
gone all wobbly.
 
K

KiwiBrian

"David Dorward" and others wrote

Many thanks to everyone who contributed to this thread.
Much appreciated.
Normal programming is now resumed.

Brian Tozer
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top