Directory path problem with PHP

Source: Internet
Author: User

Under Windows, you can use "/" or "\" to represent the directory hierarchy, while Linux can only use "/", and there is no concept of a drive letter under Linux, only the "/" symbol represents a unique root directory. Therefore, using a variable to represent the directory location, with "/" the most secure, under any system is legal. But there is one problem to be aware of, is the above mentioned Windows drive letter with the Linux root problem !

For example, $path = "/dir/", which is an absolute path, under Linux it clearly represents the Dir directory under the root directory, and in Windows, it represents the Dir directory under the current drive letter! , the "current drive letter" here refers to the drive letter where the Web server is located! For example, if your Apache is on the D-plate, then $path represents d:/dir/.

In order not to confuse, it is best to use $_server[' Document_root ') plus a relative path to represent, such as: $path = "dir/", the absolute path is: $_server[' Document_root '). $path. The directory location is the Dir directory under the root of the Web directory, it is recommended to use this global variable to represent the path, not easily confused.

Also available "." Represents the relative path representation of the current directory, this "." Represents the current directory of the script file , not the location of the Web directory tree. and ".." Represents the upper-level directory. is also relative to the location of the script file.

Directory path problem with PHP

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.