Php file name case Conversion Method Based on the Operating System

Source: Internet
Author: User
This article describes how to convert file names in case based on the operating system in php. For more information, see

This article describes how to convert file names in case based on the operating system in php. For more information, see

In php development, we need to include a file. The common code is as follows:

The Code is as follows:


If (is_file ($ fileName ))
Require $ flleName;

In windows and linux, there is no question: Assume that a d:/web/webServer/A. php file must be included.

D:/web/webServer/. when php is running in windows, the D:/web/webServer/. php is included, because windows does not differentiate the size, and an error will be reported in linux.

What makes windows load case sensitive? The Code is as follows:

The Code is as follows:


If (is_file ($ fileName )){
// The current operating system of PHP_ OS
If (strstr (PHP_ OS, 'win ')){
// Realpath ($ fileName) will convert the file name's case sensitivity/web/A. php if A. php does not exist and a. php will return/web/a. php
If (basename (realpath ($ fileName) = basename ($ fileName ))
Require $ fileName;
Else
Echo 'check the case sensitivity of the file ';
} Else
Require $ fileName;
}

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.