• Welcome to Valhalla Legends Archive.
 

Using server-side includes and parent-folders

Started by tA-Kane, June 19, 2003, 02:05 AM

Previous topic - Next topic

tA-Kane

Using server-side includes (.ssi, .shtml), how do I include a file which is in the current file's parent folder?
Macintosh programmer and enthusiast.
Battle.net Bot Programming: http://www.bash.org/?240059
I can write programs. Can you right them?

http://www.clan-mac.com
http://www.eve-online.com

Grok

Three ways I can immediately think of:
1.  If your server allows parent paths, which it shouldn't, use:
<!-- #include file="../navbar.asp" -->
2.  If your server prevents parent-paths, use explicit path from root:
<!-- #include file="/shared/navbar.asp" -->
3.  Or an alternative is to use code to solve the problem.  Use server variables and functions to get your absolute path.  If on IIS, use the FileSystemObject to GetParentPath and then build your include.
Dim fso, pathCurrent, pathParent, pathIncludeFile
Set fso = Server.CreateObject("Scripting.FileSystemObject")
pathCurrent = Request.ServerVariables("DOCUMENT_URI")
pathParent = fso.GetParentFolderName(pathCurrent)
pathIncludeFile = fso.BuildPath(pathParent, "navbar.asp")
Response.Write "<!-- #include file=""" & pathIncludeFile & """ -->


HTH,
Grok.

Eibro

I don't think that third method will work. Include files are inserted before scripts are executed.
Eibro of Yeti Lovers.

Hostile

- Hostile is sexy.

Grok

Quote from: Eibro on June 19, 2003, 02:01 PM
I don't think that third method will work. Include files are inserted before scripts are executed.

So write a script that creates a myinclude.inc containing the proper path.  Server.Transfer back to yourself, so you are read again.  This time, the include should have the correct path.