RE: [PHP] Problem with includes
| From: | Szii | Date: | Fri, 13 Oct 2000 07:17:36 +0000 |
| Subject: | RE: [PHP] Problem with includes | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-19956@lists.php.net to get a copy of this message | ||
>-----Original Message-----
>From: IroNuckles@aol.com [mailto:IroNuckles@aol.com]
>Sent: Thursday, October 12, 2000 6:51 PM
>To: php-general@lists.php.net
>Subject: [PHP] Problem with includes
>
>
>I'm trying to create a site menu which include()s html files to create a
>dynamic menu for each page. I have tried using a simple
>include("file.html");
>statement, but when I run the script, the following is printed into the HTML
>doc:
>
>Warning: Unable to access ../file.html in /directory/index.php on line 47
>
>Followed by another error:
>
>Warning: Failed opening '../file.html' for inclusion (include_path='') in
>/directory/index.php on line 47
>
>Any help or insight would be appreciated. Thanks!
>
include() and require() are odd. They'll look in the current directory first,
then in the .ini's include dirs, and then they'll throw an error.
root
level1
file_include1
level2
script_php.php4
if you run script_php.php4 from it's own directory, you can use
include("../level1/file_include1")
If you're in the root, and run ./level2/script_php.php4 and have that same
include, it'll hurl saying
that it can't find it. It's looking in the directory RELATIVE TO THE
EXECUTION DIRECTORY
instead of really being relative to the script file. In this example, it's
being executed from "root"
and therefore it looking in /root/../level1/file_include1 and not looking
for the path relative to the
executing script file. This is mostly an oddity in
You can specify include dirs in you php.ini file, and I'd recommend doing
that. Then when you
include("file_include1") it'll search in it's "known include
directories"
and will find it accordingly.
As another alternative, use absolute paths and you're find.
include("/root/level1/file_include1")
will simply always work, until you switch drives under Windows. (C:\
instead of D:\) This is
non-existant on Un*x since it's all one big filesystem. This has the
advantage of your knowing
(as a programmer) EXACTLY what's being included and from where. The other
way (ini file)
may mask certain problems and make debugging a little more difficult.
Peace.
-Szii