PHP pre-defined constant DIRECTORY_SEPARATOR-PHP source code

Source: Internet
Author: User
Tags file separator
In php, DIRECTORY_SEPARATOR is the most common global variable in cms. Let's take a look at the example of using a PHP pre-defined constant DIRECTORY_SEPARATOR, as shown below. In php, DIRECTORY_SEPARATOR is the most common global variable in cms. Let's take a look at the example of using a PHP pre-defined constant DIRECTORY_SEPARATOR, as shown below.

Script ec (2); script

DIRECTORY_SEPARATOR is a command for displaying system delimiters. DIRECTORY_SEPARATOR is an internal constant of PHP and can be directly used without any definition or inclusion.

As we all know, in windows, the path separator is (of course/can run normally On some systems), and in linux, the path separator is/, which leads to a problem, for example, if the development machine is windows and there is an Image Upload program, the directory for saving the specified upload files on the debugging machine is: define ('root', dirname (_ FILE __). "upload"). Local debugging is normal, but errors may occur when uploading data to the linux server.

This problem lies in the file separator, Which is habitually used as a file Separator on windows, but on linux, people do not know this identifier, but they only know /, so we need to introduce the following php built-in variable: DIRECTORY_SEPARATOR.
The preceding statement can be rewritten as follows:

Define ('root', dirname (_ FILE _). DIRECTORY_SEPARATOR. "upload ");

In this way, the error will not occur.
For example, define ('s _ root', dirname (_ FILE _). DIRECTORY_SEPARATOR) is written in discuz );
Back to the problem itself, DIRECTORY_SEPARATOR is a php built-in command that returns the path separator related to the operating system, which is returned on windows and/on linux or unix-like /, this is the difference. It is usually used when defining the path containing files or uploading and storing directories.
.
Define ('root', dirname (_ FILE _). "\ upload ");

Local debugging is normal, but an error occurs after being uploaded to the linux server. Therefore, the code above is written as follows:

Define ('root', dirname (_ FILE _). DIRECTORY_SEPARATOR. "upload ");

Tip: You can use the get_defined_constants () function to obtain all PHP constants. For example:

Print_r (get_defined_constants (); // get_defined_constants () returns all constant Arrays

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.