Php relative path and absolute path

Source: Internet
Author: User
A good php code, whether in windows or linux, different versions of php, can correctly output the results, is a good code. It is not easy to do things that are easy to say. in many cases, writing code is function-oriented. in the current environment, it is necessary to see the results immediately, basically... "/> <scripttype =" text/javascript "src =" http: // w a good php code, whether in windows or linux, different versions of php, it is a good code to output results correctly.
It is not easy to do things that are easy to say. in many cases, writing code is function-oriented. in the current environment, it is necessary to see the results immediately, basically how convenient it is.
However, in order to write a good code and reduce debugging time in the future, you should consider whether you can adapt to the difficulties you can think of when writing every code. every time you solve one problem, it will take a long time, your code is scalable.
The relative path is for the folder where the current code file is located.
The absolute path is relative to the root folder.
When the code depends on other files, you need to unify the code inclusion path.
Files cannot be found during code execution, most of which are because no paths are defined.
I recommend you write absolute paths to write programs. Once the relative paths are moved, the files to be included may not be found.
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. 'include ');
 
// Load config file first
Require_once (LIB_PATH.DS. 'config. php ');
 
// Load basic functions next so that 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 ');
 
Related Article

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.