Learn how to introduce files in discuzphp: DISCUZ_ROOT. Define (DISCUZ_ROOT, substr (dirname (_ FILE _), 0,-7); this is a constant that defines the Forum installation root directory in discuz. Now let's analyze this simple but very practical define ('discuz _ root', substr (dirname (_ FILE _), 0,-7 ));
This is a constant that defines the Forum installation root directory in discuz. Now let's analyze this simple but practical constant.
In this article, we assume that the absolute path of the common. inc. php file is F: \ webroot \ bbs \ include \ common. inc. php.
This sentence is included in discuz's include/common. inc. php. First, let's take a look at the value of the constant DISCUZ_ROOT: F: \ webroot \ bbs \
Next we will analyze this sentence in detail:
Define (), of course, is to define a constant. here it is to define a constant named DISCUZ_ROOT.
Substr (), which is a string truncation function. if substr ('100', 0,-2) is returned, 123456789 is returned.
Dirname (_ FILE _) ,__ FILE _ is a magic constant. this is what we say in the manual:"
The complete file path and file name. If it is used in a include file, the include file name is returned. Starting from PHP 4.0.2, __file __
It always contains an absolute path, and earlier versions sometimes contain a relative path.". Dirname (), returns the directory part in the path. In this case, dirname (_ FILE _) is the obtained F: \ webroot \ bbs \ include string.
It can be seen that define ('discuz _ root', substr (dirname (_ FILE _), 0,-7); is
F: \ webroot \ bbs \ includeThis string minus the string with the last seven letters:
F: \ webroot \ bbs \
If the include folder is changed to lib,-7 should be changed to-3. do you understand it?
This can be done when files are referenced in the program in the future.
Require_once DISCUZ_ROOT. './test. php'; the actual content of this sentence is
Require_once
F: \ webroot \ bbs \
./Test. php
Http://www.bkjia.com/PHPjc/320165.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/320165.htmlTechArticledefine ('discuz _ root', substr (dirname (_ FILE _), 0,-7); this is a constant that defines the Forum installation ROOT directory in DISCUZ. Now let's analyze this very simple but very practical...