PHP relative path and absolute path _php tutorial

Source: Internet
Author: User
A good PHP code, whether put on Windows or Linux, different versions of PHP, can correctly output the results, is a good code.
Said easy things, do not very easy, often write code are functional guidance, the current environment, to catch the time immediately see the effect, basic is how convenient how to come.
But in order to write a good code and reduce debugging time later, write each code to consider whether it can adapt to the difficulties you can think of, each time to solve one, accumulate, your code will be flexible.
The relative path is for the folder where the current code file resides.
The absolute path is relative to the root folder.
When your code needs to depend on other files, you need to include the path to the uniform code.
The code did not find the file when it was executed, mostly because the path was not defined.
I recommend you write the absolute path to write the program, the relative path once moved, it is easy to find the file to be included.
PHP functions and constants used
DirName
__file__
Directory_separator
It is recommended to write an initialization file initialize.php
Define the core paths
Define them as absolute paths to make sure that require_once works as expected

Directory_separator is a PHP pre-defined constant
(\ for Windows,/for Unix)
Defined (' DS ')? Null:define (' DS ', directory_separator);

Defined (' Site_root ')? Null:define (' Site_root ', DirName (__file__));

Defined (' Lib_path ')? Null:define (' Lib_path ', site_root. DS. ' includes ');

Load config file first
Require_once (Lib_path. DS. ' config.php ');

Load basic functions next so, everything after can use them
Require_once (Lib_path. DS. ' functions.php ');

Load Core Objects
Require_once (Lib_path. DS. ' session.php ');
Require_once (Lib_path. DS. ' database.php ');

Load database-related Classes
Require_once (Lib_path. DS. ' user.php ');

http://www.bkjia.com/PHPjc/621603.html www.bkjia.com true http://www.bkjia.com/PHPjc/621603.html techarticle a good PHP code, whether put on Windows or Linux, different versions of PHP, can correctly output the results, is a good code. It's easy to say, it's not very light .

  • 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.