PHP Predefined Constants Directory_separator Detailed

Source: Internet
Author: User
Tags constant file separator php and

Directory_separator is a command that displays the system separator, directory_separator is the internal constant of PHP and can be used directly without any definition or inclusion.

As we all know, under Windows the path separator is (of course/on some systems also can be normal operation), on Linux the path of the separator is/, which caused a problem, such as the development of the machine is Windows, there is a picture upload program, The upload files specified on the debug machine are saved in the directory: define (' ROOT ', DirName (__file__). Upload "), it is normal to debug locally, but when uploaded to the Linux server you will find that there are errors.

This problem is in the file separator, Windows habitually used as a file separator, but on Linux people do not know this logo, others only know/, so we will introduce the following PHP built-in variable: directory_separator.
The above wording can be rewritten as the following error-free notation:

Define (' ROOT ', DirName (__file__). Directory_separator. " Upload ");

This will ensure that there is no error.
For example Discuz inside is written like this: define (' S_root ', DirName (__file__). Directory_separator);
Back to the problem itself, Directory_separator is a PHP built-in command that returns the path separator associated with the operating system, returns on Windows, and returns on Linux or Class UNIX, which is the difference It is usually used when defining the include file path or uploading the save directory.

Define (' ROOT ', DirName (__file__). \upload ");

Debugging locally is normal, but it can go wrong after uploading to a Linux server. So, as the code of the rigorous writing:

Define (' ROOT ', DirName (__file__). Directory_separator. " Upload ");

Tip: You can use the function get_defined_constants () to get all the 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.