简体   繁体   中英

Relative, absolute and bloody quantum paths in PHP!

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

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';

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM