note 46789 added to function.include
| From: | legeis at lycos dot co dot uk | Date: | Sat, 23 Oct 2004 09:27:15 +0000 |
| Subject: | note 46789 added to function.include | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-78989@lists.php.net to get a copy of this message | ||
Don't know if this is overkill but this is what i came with up to compensate for include
function directory problems
you have eg.
/dir1/file1.php
/dir1/dir2/file2.php
/dir1/includefile.php
file1.php
<? include('includefile.php')?>
file2.php
<? include('includefile.php')?>
will give you "Warning: include('includefile.php'): failed to open stream: No such
file or directory...."
so i came up with
file1.php
<?
$dirs = array("",".","..","../..");
$amount = substr_count($_SERVER['PHP_SELF'], "/");
$dir = "{$dirs[$amount]}/includefile.php";
include($dir)
?>
file2.php
<?
$dirs = array("",".","..","../..");
$amount = substr_count($_SERVER['PHP_SELF'], "/");
$dir = "{$dirs[$amount]}/includefile.php";
include($dir)
?>
hope it helps and if there is a better way besides include_path please let me know
----
Manual Page -- http://www.php.net/manual/en/function.include.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+46789
Delete -- http://master.php.net/manage/user-notes.php?action=delete+46789&report=yes
Reason: bad code -- http://master.php.net/manage/user-notes.php?action=delete+46789&report=yes&reason=bad+code
Reason: spam -- http://master.php.net/manage/user-notes.php?action=delete+46789&report=yes&reason=spam
Reason: useless example -- http://master.php.net/manage/user-notes.php?action=delete+46789&report=yes&reason=useless+example
Reason: contains commercial links -- http://master.php.net/manage/user-notes.php?action=delete+46789&report=yes&reason=contains+commercial+links
Reason: useless note -- http://master.php.net/manage/user-notes.php?action=delete+46789&report=yes&reason=useless+note
Reject -- http://master.php.net/manage/user-notes.php?action=reject+46789&report=yes
Search -- http://master.php.net/manage/user-notes.php