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