PHP _php instance based on the method of converting file name capitalization from the operating system

Source: Internet
Author: User

In the development of PHP we want to include a file The usual code is this:

Copy Code code as follows:

<?php
if (Is_file ($fileName))
Require $flleName;

Running under Windows,linux doesn't ask a question: Suppose you want to include a d:/web/webserver/a.php file now

When the value is passed, the d:/web/webserver/a.php will also include d:/web/webserver/a.php when running under Windows, because Windows is not case-sensitive and will be given an error when placed under Linux.

Is it possible to be case-sensitive when loading Windows? The code is as follows:

Copy Code code as follows:

if (Is_file ($fileName)) {
Php_os the currently running operating system
if (Strstr (Php_os, ' WIN ')) {
Realpath ($fileName) Converts the case of the file name/web/a.php if a.php does not exist and a.php returns/web/a.php
if (basename (Realpath ($fileName)) = = BaseName ($fileName))
Require $fileName;
Else
Echo ' Please check the file case ';
}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.