View Full Version : Include confusion
gorilla1
03-16-2003, 05:08 PM
From one subdirectory I want to include a file from another subdirectory. I tried both of the below, but neither worked. Is there a way to do this?
<!-- #include virtual="http://mysite.com/admin/admin_enter.asp" -->
<!--#include file="http://mysite.com/admin/admin_enter.asp"-->
I also found that if I tried to include a file from a child sub directory of the directroy from which the script is running did not work:
<!--#include file="admin/admin_enter.asp"-->
Well, this works:
<%@ LANGUAGE="VBSCRIPT" %><% Response.Buffer=True %>
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=iso-8859-1">
<meta name="generator" content="Adobe GoLive 4">
<title>Admin main</title>
</head>
<body>
<!--#include file="./test/test.inc"-->
<!--#include file="test/test.inc"-->
</body>
</html>
Now, on includes. There are three sort a paths:
- real path : example c:\test\test.asp (NOT GOOD)
- virtual (and relative-paths : example http://www.codingforums.com/newreply.php + for relative paths example : code above. first line (AHA)
serverside includes need virtual paths. The path you see in your browser when you load the page, includes the vitual path of the app. If you use an include in that file, you just use the realtive path from the refered page.
If you want to go to the parent folder, use
<!--#include file="../test/test.inc"-->
NOTE : parent paths are (should) not be allowed on production servers (for security reasons)
dominicall
03-21-2003, 07:29 AM
Try and get into the habit of using <!-- #include virtual="/somefile.asp" --> rather than include file...
raf was absolutely right about parent paths... if you use <!-- #include file= ..... --> rather than <!-- #include virtual= .... --> and the server has parent paths turned off then you'll run into problems.
<!-- #include virtual=.... --> always starts at the root of the site so all you need to do code your include tag from root, like so...
<!-- #include virtual="/includes/somefile.asp" --> or <!-- #include virtual="/files/someotherfile.asp" -->
Hope that helps
dominicall :D
whammy
03-22-2003, 03:06 AM
dominicall is 100% correct.
This is what include virtual is designed for... for instance:
<!-- #include virtual="/blah/halb.asp" -->
would include a file named "halb.asp" from an initial SUBdirectory (from your root) named "blah" into EVERY application that used this include technique - even if your application was rooted 20 folders deep, or AVOBE "blah" itself. ;)
P.S. This doesn't include folders above your root directory - a future chapter will be devoted to that... er- well wait a minute! This isn't a book... lol
Anyway - that should be easy to figure out once you get this and understand Server.MapPath() in VBScript which maps out local paths to files on the server's hard drive. ;)
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.