Need help with include() function

Hello, I am having trouble with the include() function. I have my index.html file in the document root directory, but when I try to tell it to include a file from the document root directory by entering include(’/external/menu.html’) it won’t work. For some reason it doesn’t like searching through the document root directory when I use a file that is in the document root directory. It works fine if I do the same thing from a subdirectory though. Here is the error I get:

Warning: main(/external/menu.html): failed to open stream: No such file or directory in C:Program FilesApache GroupApache2htdocsindex.html on line 21

Warning: main(): Failed opening ‘/external/menu.html’ for inclusion (include_path=’.;c:php4pear’) in C:Program FilesApache GroupApache2htdocsindex.html on line 21

I don’t know if it is suppose to do that or not.
I am pretty new to PHP, so any help would be greatly appreciated.

Well obviously you are on a windows system. I am not sure if it’s the same on a windows system or not, however when you type the INCLUDE with a path to the file and lead it off with a forward slash / that is not the document root. that is the system root. (in linux anyway).

If you want the doucment root, you can either specifiy the intire path (relative to c:) or a relative path from your current location.

You are in C:inetpubwwwroothomescripts
you want to include a file located in c:inetpubwwwroothome

You can either do either of the following:

include (‘’)
include (’…’)

Again I am not sure how they work with the windows. In unix/linux it would be

include (’/inetpub/wwwroot/home/’)
include (’…/’)

Hope this helps

May I ask a quick question on the subject… the two dots before the slash tell the server to go up 1 directory… Right?

Yes. the double dot … is to navigate to the PARENT directory of the CURRENT directory. In my scenario above if the script is run from The SCRIPT directory and the included file is in the HOME directory (which is the parent of the script directory), then you can use the double dot notation to navigate to it.

Again… I reiterate that this works in a *nix environment. Not sure if it works in a windoze environement.


Yes it does work in Windows. I was just hoping I didn’t have to do it this way. I guess it doesn’t really matter though because it will still work fine. Oh well, thanks a lot.

  • Emir
Sponsor our Newsletter | Privacy Policy | Terms of Service