How to convert the case of file names in PHP according to the operating system_PHP tutorial

WBOY
Release: 2016-07-13 10:24:52
Original
1128 people have browsed it

In PHP development, when we want to include a certain file, the usual code is like this:

Copy code The code is as follows:

if(is_file($fileName))
require $flleName;

There is no problem when running under windows and linux: Suppose now you want to include a file D:/web/webServer/A.php

D:/web/webServer/a.php was misrepresented when passing the value. When running under windows, D:/web/webServer/A.php will also be included, because windows is not size-sensitive. If you put it under linux, an error will be reported

How about making it case-sensitive when loading in windows? The code is as follows:

Copy code The code is as follows:

if(is_file($fileName)){
//PHP_OS currently running Operating system
if(strstr(PHP_OS,'WIN')){
//realpath($fileName) will convert the case of the file name /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 'Please check the file Case ';
}else
  require $fileName;
}

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/825313.htmlTechArticleIn the development of PHP, we want to include a certain file. The usual code is like this: Copy the code and the code is as follows: ? php if(is_file($fileName)) require $flleName; It doesn’t work under windows or linux...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!