Jump to content
wildman

#INCLUDE FILE in another directory

Recommended Posts

my include file works, provided both the program and i.f. it reads and includes are in the same directory.

Now, i.f. is in 'root' and 4 programs , that feed off it, are in different 'dirs.' I need to put correct path into the <!-- #include file= ??? --> directive, but no matter what I put in computer still can't find it.

 

Is this the answer? I've tried it, it doesn't work.

 

IncPath = Server.MapPath("/ffile.inc"); //....... maybe something like this.

Edited by wildman

Share this post


Link to post
Share on other sites

If you include a virtual file then the virtual path will start with the document root for the server, so if that path starts with a slash then you can start at the root and go from there.

Share this post


Link to post
Share on other sites

Specify a virtual file:

 

http://www.w3schools.com/asp/asp_incfiles.asp

 

I'm only a blue-collar clerk.

What does that mean? I feel like you're about to give an excuse why you can't or don't want to learn.

 

If you don't understand something I said then ask about it. You used "root" in your question, do you understand what that is?

Share this post


Link to post
Share on other sites

I've worked in computers and programming 35 yrs, tho most of that in DOS. Not very fluent in windows.

 

ok, i'm pretty sure I know what you mean by 'virtual' (computer memory). and 'server' (as opposed to the client) and 'root' (dir structure). PathPointer = Server.MapPath("/includefile.inc") run on the root returns -

PathPointer = E: \web\ccs2468com0\htdocs\includefile.inc //ccs2468com0 is my website

This I put in the #include directive in the program - other directory. Apparently the computer still can't find the file.

Maybe I need to take the "htdocs" out, seeing that my file is in the root.

 

i'm not sure what you mean by "document root for the server"

Edited by wildman

Share this post


Link to post
Share on other sites

I don't mean virtual as in computer memory, a virtual file or folder is different than a physical file or folder. A virtual directory in the web server could be configured to point to any physical directory, but it uses a virtual path which doesn't actually exist other than to point to the physical location. It's like an alias, a different name for the same thing.

 

You can't use Server.MapPath for including files, because including the files happens before the code gets executed. So it happens before Server.MapPath runs. ASP is fun that way.

 

The document root is whatever directory the server looks in when you load the root directory, e.g. http://localhost/. That URL points to a particular directory on your server, that directory is the document root for the web server.

 

When you use #include with the virtual keyword, then I believe your file path starts at the document root. So, no matter which directory you're in, the path to the include file always starts at the document root. You can use that to always include the same file from any other directory.

Share this post


Link to post
Share on other sites

I wrote a program called GetPath.asp, which is really no more than to just run server.MapPath("includefile.inc") that then display the results. My website is "ccs2468.com/" so I put http://ccs2468.com/GetPath.asp in the url (I assume that's the root dir) and run it. The result is - E \web\ccs2468com0\htdocs\includefile.inc. Now I'm not sure where the htdocs came from, but I'm pretty sure that would be considered a subdirectory on the root, which there's no such thing, so I took it out.

 

So now, with my ftp program, I change dirs. to ccs2468.com/books/books.asp and insert this directive -

<!-- #include file="E \web\ccs2468com0\includefile.inc" > and run books.asp. It makes the program crash.

Edited by wildman

Share this post


Link to post
Share on other sites

The include line doesn't end correctly.

 

You're still not using virtual files. How about this:

 

<!-- #include virtual="/includefile.inc" -->

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×