|
Posted by Hilarion on 07/08/05 16:26
> I think I have tried your suggestion, although I am not sure I follow
> you paragraph above. I have taken my code shown below
>
> <img src="library_files/logo.gif" alt="Mortgage Loans" border="0"
> width="128" height="122"></a><br><br></td>
> <a href="index.html"><font size="1">Home</font></a></p>
>
> and added a ../ so that it now read
>
> <img src="../library_files/logo.gif" alt="Mortgage Loans"
> border="0"
> width="128" height="122"></a><br><br></td>
> <a href="index.html"><font size="1">Home</font></a></p>
>
> library_files is a directory right under the root dir, and index.html
> is in the root.
If you use "../", then it's still relative path.
If you are using parameter wrapping, then you should use
absolute path (server absolute or Internet absolute):
<img src="/library_files/logo.gif" alt="Mortgage Loans"
border="0"
width="128" height="122"></a><br><br></td>
<a href="/index.html"><font size="1">Home</font></a></p>
Notice that I used absolute path also for HREF.
> I am lost on what is the server absolute path.
"index.html", "../dir/some_file.ext", "some_path/another.file" are
relative paths and they are evaluated (when appear in HTML output)
by web browser relatively to current document path (warning:
if current document path ends with "/" sign, then it's treated
as a folder, but if it's not, then last part is treated as file
name and is stripped from path).
If curren document path is:
http://some.domain.com/some_dir/some_doc.html
then above paths lead to:
http://some.domain.com/some_dir/index.html
http://some.domain.com/dir/some_file.ext
http://some.domain.com/some_dir/some_path/another.file
If current path is:
http://some.domain.com/another_dir/another_doc.php/param1/param2
then above paths lead to:
http://some.domain.com/another_dir/another_doc.php/param1/index.html
http://some.domain.com/another_dir/another_doc.php/dir/some_file.ext
http://some.domain.com/another_dir/another_doc.php/param1/some_path/another.file
If current path is:
http://some.domain.com/another_dir/another_doc.php/param1/param2/
then above paths lead to:
http://some.domain.com/another_dir/another_doc.php/param1/param2/index.html
http://some.domain.com/another_dir/another_doc.php/param1/dir/some_file.ext
http://some.domain.com/another_dir/another_doc.php/param1/param2/some_path/another.file
If you are using paths with "../" inside them, then remember that it's
evaluated on browser side, so you can't navigate this way above the
webserver root.
Absolute paths are:
- server absolute path - starts with "/" sign, which means that all
given paths are relative to webserver root folder (which may be and
in most cases is different than server filesystem root),
- internet absolute path - starts with "protocol" prefix eg. "http://",
"mailto:" etc. and gives absolute and complete URL to resource.
> And depending on what
> you mean is there a way to change the directory paths programatically
> without out having to rewrite my original code?
>
> PS I know how to fill in a php variable and pt the variable in front
> to create a correct path, as in
>
> <?
>
> $URL = "http://www.domain.com/";
>
> ?>
>
> <img src="<? echo $URL; ?>library_files/logo.gif" alt="Mortgage
> Loans" border="0"
> width="128" height="122"></a><br><br></td>
> <a href="<? echo $URL; ?>index.html"><font
> size="1">Home</font></a></p>
>
> I jsut would prefer to change or set the path at the beginning of a
> file rather than have to add the code to every file and link.
The best way would probably be to change all your relative URL paths
to server absolute paths, but this requires rewriting most of your
PHP / HTML code.
You have other options which are not recomended but will work.
They are based on <base> tag (inside <head> tag of <html> tag).
If your <head> section is allready placed in one PHP/HTML file which is
included by all other files, then using <base> tag would require only
change in this one file. If not, then you'll have to change each
file which contains (or should contain) <head> section.
If you have http://some.domain.com/some_path/some_script.php document
which is called by http://some.domain.com/some_path/some_script.php/param1/param2
URL and want all relative paths inside this document be calculated
basing on http://some.domain.com/some_path/some_script.php path, then
you should place this path in <base> tag like this:
<html>
<head>
<base href="http://some.domain.com/some_path/some_script.php" />
...
</head>
<body>
...
</body>
</html>
If <head> section is defined in one file which is included by other PHP
files which are located in different paths, then the way you should use
<base> tag in it depends on the way you use relative paths in your
documents. If the relative paths are relative to one specific folder
(same for all documents), then you should use <base> as above, but
if the paths are relative to the folder which contains the called
document, then base tag should be dynamically filled with path to
called document like this:
<html>
<head>
<base href="http://some.domain.com<?php echo htmlspecialchars( $_SERVER[ 'SCRIPT_NAME' ] ); ?>" />
...
</head>
<body>
...
</body>
</html>
Hilarion
Navigation:
[Reply to this message]
|