Here is directory structure
- /global.php
- /includes/class_bootstrap.php
- /includes/init.php
- /plugins/myplugin.php
Here is codes in these files
/start.php
require('./includes/class_bootstrap.php');
/includes/class_bootstrap.php
define('CWD', (($getcwd = getcwd()) ? $getcwd : '.'));
require_once(CWD . '/includes/init.php');
/plugins/myplugin.php
require_once(dirname(__FILE__).'../global.php');
And as far as I am understanding the problem is in class_bootstrap.php file coz it's generating wrong path for CWD here is error:
Warning: require_once(C:/wamp/www/vb4/plugins/includes/init.php) [function.require-once]: failed to open stream: No such file or directory in C:/wamp/www/vb4/global.php on line 35
As you can see "C:/wamp/www/vb4/plugins/includes/init.php" is wrong path.
The MAIN PROBLEM is that I can edit only myplugin.php file other files are CMS core files and should not be changed.
How can I fix this issue?
If you need to determine the base path of a set of scripts, you should not rely on the "current working directory." This can change from executing environment to executing environment.
Instead, base it on a known path.
/includes/class_bootstrap.php
knows that it's going to be one directory down from where the base path is going to be, so it can do this:dirname
gets the directory name given in the passed string. If__FILE__
returnsC:/wamp/www/vb4/plugins/includes/class_bootstrap.php
, thendirname
will returnC:/wamp/www/vb4/plugins/includes
. We then append/../
to it and then callrealpath
, which turns that relative..
into a real directory:C:/wamp/www/vb4/plugins
Phew.
From that point forward,
CWD
will operate as you expect. You canrequire_once CWD . '/includes/init.php'
and it will correctly resolve toC:/wamp/www/vb4/plugins/includes/init.php
Also, this may sound stupid but "vb4" may be referring to vBulletin 4, in which case your plugin may already have access to the configuration information that it exposes, including handy things like paths. This may make this entire exercise unnecessary. I intentionally know nothing about vB, otherwise I would point you at their dev docs.