php's method for converting file names to case based on the operating system

  • 2021-01-11 01:55:11
  • OfStack

In the development of php we would include a file and the usual code would look like this:


<?php  
     if(is_file($fileName))
        require $flleName;

In windows linux running under no questions: suppose will now include a D: / web webServer/A php file

In the value of misinformation D: / web webServer/a php runtime will be put under windows D: / web webServer/A php included, because windows is not distinguish between size, under linux will be an error

What about case sensitive windows loading? The code is as follows:


if(is_file($fileName)){
   //PHP_OS   The operating system that is currently running 
   if(strstr(PHP_OS,'WIN')){
     //realpath($fileName)  Will convert the case of the file name   /web/A.php  if A.php There is no and a.php Will return /web/a.php
        if(basename(realpath($fileName)) == basename($fileName))
            require $fileName;
        else
            echo ' Please check the case of the file ';
    }else
        require $fileName;
}


Related articles: