Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

include (../"varDefs.php") does not work?

Status
Not open for further replies.

scriggs

IS-IT--Management
Jun 1, 2004
286
GB
I have a file varDefs.php which holds my global variables and file locations and is located in the root of my web space (e:\NewIntranet\varDefs.php).

I have my scripts in a directory called 'scripts' and need to include the varDefs in my script. I have tried:

Code:
include ("../varDefs.php");

but it does not seem to work. I get the error
"Warning: mailmergedocument(../../varDefs.php): failed to open stream: No such file or directory in E:\NewIntranet\scripts\files.inc.php on line 280"
 
and did you make sure that it's written in the same cases ??

so not \Scripts\ or vardefs.php ??

some webservers are case sensitive
 
Thanks, I have checked the case - this works if I move the varDefs.php to the scripts directory and then remove the '../' element. I assumed PHP does not support '../' but I can't find anthing to confirm/give an alternative.
 
If you have a folder that is used for common files to be included I recommend that you add that folder to the include path. That means it will be searched and you need not path info for that file.
Code:
set_include_path(get_include_path().PATH_SEPARATOR."/the/path/to/the/include/folder");

After that is set you can just say:
include("varDefs.php");

Also, be aware:
PHP Manual said:
Files for including are first looked in include_path relative to the current working directory and then in include_path relative to the directory of current script. E.g. if your include_path is ., current working directory is / you included include/a.php and there is include "b.php" in that file, b.php is first looked in /www/ and then in / If filename begins with ../, it is looked only in include_path relative to the current working directory.
 
Thanks for that DRJ478.

Where do I add the set_include_path? Is this in the PHP document that I am calling from? If so then I may aswell set the full path to the document?

How would I set it? My addresses are:

OR
e:\WASP\vardefs.php
 
It is important to be aware that the include path is from the file system prospective. Sometimes people mix that up with the DOCUMENT_ROOT of the web server, which is different.

I would recommend an include itself that sets these environment parameters. It then should be included first in the script with an absolute path to it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top