Question

I am building a web app (a forum), and it is to be integrated into various websites. The idea is that the folder location storing all the files is variable so that a webmin can put the forum wherever they like. I have, as usual, some PHP included files.

Say I have global.php and envars.php and want them included in app_root.php. The first two are stored in ./global/, relative to app_root.php. Now, when I use ./ I get a file not found error. If I use just global/ (no prepended slash), I get the same error.

I really need help on this :-(

The paths need to be relative to app_root.php and can't be absolute - the abs. path varies per installation.

Thanks for reading,

James

Was it helpful?

Solution

This problem is normally solved by creating a constant with an absolute path to the application.

Something like this in your app_root.php file

define('ROOT_PATH', dirname(__FILE__));

Then, to include other files just use something like

include ROOT_PATH . '/dir/file.php';
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top