Forum Moderators: open

Message Too Old, No Replies

php template path difficulties

         

ukgimp

3:36 pm on Feb 14, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hello

This is css and website issues related, sorry if is is not in the best forum.

I am developing a php template driven site which is static in some paces and dynamic in others.

I have header, middle and footer. The problem comes when I move to a different folder. The css does not work as I have a relative path. Apart from linking from the absolute path (C:/dir/dir2/css/main.css) is there any advice that can be offered.

This has me stumped!

Cheers

korkus2000

3:53 pm on Feb 14, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If your css folder is off the root you should be able to use /css/main.css right? This issue made me use absolute links with my templates something always made a bug.

ukgimp

4:17 pm on Feb 14, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks Korkus

Trouble is though it may not be in the root so I am still left with the C:/etc option (which seems cack).

How dangerous is it to have the full path so that people can see it?

korkus2000

4:19 pm on Feb 14, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Can you not use the domain name or is this a multiple domain include? I have set up an image/css/whatever domain to kind of have a namespace. This way I have one path to that domain name.

ukgimp

4:28 pm on Feb 14, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yes thats it. I could use the domain name. Developing locally so I would have to change that at a later date before upload.

Cheers

universalis

3:00 pm on Feb 17, 2003 (gmt 0)

10+ Year Member



If you're doing stuff like includes, you can use DOCUMENT_ROOT. This will mean that the code will work on different servers with different paths. For example:

<?php include($_SERVER["DOCUMENT_ROOT"]."/includes/menu.php");?>

This works on my desktop (Apache 2 on Win2k) and on my server (Zeus 4.2 on Solaris 9).

andreasfriedrich

5:08 pm on Feb 17, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



korkus2000 [webmasterworld.com] wrote at 03:53 AM on Feb. 14, 2003 in message #2 [webmasterworld.com]
If your CSS [w3.org] folder is off the root...

How could it be not off the URI namespace root? If it were not there would be no way to access it by using a URL and external style sheets need to be included by a URL reference (unless you want to use a local stylesheet). In fact if it were not off the URI namespace root it would not be at all, since there is nothing within the URI namespace that is not somewhere below root.

For including PHP [php.net] files using [url=http://www.php.net/include]include() [php.net][/url] or [url=http://www.php.net/require]require() [php.net][/url] this may be otherwise (i.e. they need not reside below the URI root but they will reside below the filesystem root) since they take a local path as an argument as well as a URI.

Andreas

ukgimp

12:31 pm on Feb 25, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Sorry the bring this up again, but :)

I am still having what seems to be rudimentary difficulties with this in some cases, it could live with it if it did not work across the board but it works when calling a CSS file from a header page.

include("C:phpdev/www/dir1/dir2/file.php");

The above works but when I try an use the absolute path like this:

/dir1/dir2/file.php

It throws a wobbler and says it cannot find that path. Am I missing something?

Warning: Failed opening '/dir1/dir1/file.php' for inclusion (include_path='.;C:/phpdev/php/includes;C:/phpdev/php/class') in

HarryM

2:16 pm on Feb 25, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



My own (very inelegant) solution to this problem is to only have 2 levels. Index and sitemap pages, etc, are at level 0 (off the root) and everything else is contained in directories at level 1.

Therefore the format "../directory/page.inc" works for all level 1 pages. E.g. linking to "../css/..." or selecting includes "../includes/..."

The directory structure is flat, but the linking structure can still appear to be a pyramid. It works for a few 100 pages, but there is probably an upper limit where a true directory structure is required for maintainability.