Function of DIRECTORY_SEPARATOR in PHP, phppathseparator

Source: Internet
Author: User
Tags file separator zend framework

Function of DIRECTORY_SEPARATOR in PHP, phppathseparator


DIRECTORY_SEPARATOR is an internal constant of php. It is used to display system separator commands and can be directly used without any definition or inclusion.

In windows, the path separator is \ (of course/can also run normally On some systems). 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 storing the specified upload files on the debugging machine is:

Define (ROOT, dirname (_ FILE _). "/upload ");

Local debugging is normal, but errors may occur when uploaded to the linux server. So php introduced the DIRECTORY_SEPARATOR variable, which can be rewritten:

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

DIRECTORY_SEPARATOR is a php built-in command that returns path separators related to the operating system. It returns \ on windows, and returns/on linux or unix-like, it is usually used when defining the path containing files or uploading and storing directories.
For example:

View plaincopy to clipboardprint?
Const DIR_SEP = DIRECTORY_SEPARATOR; // path separation in Windows/
Private function _ construct ()
{
$ This-> _ options = array (
Template_dir => templates. self: DIR_SEP, // directory where the template file is located
Cache_dir => templates. self: DIR_SEP. cache. self: DIR_SEP, // cache file storage directory
Auto_update => false, // whether to regenerate the cache when the template file is changed
Cache_lifetime => 0, // cache lifecycle (minutes), 0 indicates permanent
Suffix =>. html // template file suffix
);
}


-> What is the role in PHP?

-> It is equivalent to a pointer in C ++.
Point to the value in $ fields.
In some cases, $ pubname = $ fields [value] cannot be used.
For example, in the zend framework
$ Tid = $ this-> _ request-> getParam ('tid ');
It indicates $ _ REQUEST ($ _ GET, $ _ POST, and $ _ COOKIE set) in $ this (this webpage)
GetParam value in (equivalent to $ _ GET)

How is DIRECTORY_SEPARATOR used ?? I know what it means.

Php's built-in variable 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, it can run normally On some systems. is Microsoft's operating system user-friendly? Is it not accurate enough ?), In linux, the path separator is/, which leads to a problem. For example, if your development machine is windows, you have an image upload program, the directory for saving the uploaded files you specified on your debugging machine is: define ('blogguy. CN_ROOT ', dirname (_ FILE __). "/upload"), local debugging is normal, but you will find errors when uploading to the linux server.

Yes, many websites have been so experienced. They were so impressed when they were in the first place.

This problem lies in the file separator. in windows, we often use/as the file separator, but on linux, people do not know this identifier /, so we need to introduce the following php built-in variable: DIRECTORY_SEPARATOR.

The preceding statement can be rewritten as follows:
Define ('blogguy. CN_ROOT ', dirname (_ FILE _). DIRECTORY_SEPARATOR. "upload ");
In this way, the error will not occur.

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.