How to introduce files in discuzphp: DISCUZ_ROOT_PHP tutorial-php Tutorial

Source: Internet
Author: User
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...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.