4

Is there any way to call require_once with some "case insensitive flag" ? In windows it's okay, but linux is case sensitive. Is there any way to override ? Thanks

4

3 回答 3

2

Sure, load

strtolower($className . ".php")

and name your files in lowercase.


Regardless of how you try to load your files, only the lowercase version will ever be loaded.

于 2013-01-05T11:25:26.263 回答
0

您可以在每次加载时使用它来自动加载适当的类。您必须更改目录取决于您的项目。您可以使用 echo 或 print_r 打印每次调用某些内容时加载的类。您所有的类名也必须具有相同的格式,例如,className.class.php,例如 Dashboard.class.php、Category.class.php。您可以使用 ucwords 将首字母大写。

function __autoload($className) 
{
    if (file_exists(__DIR__ . '/../library/' . strtolower($className) . '.class.php')) 
    {
        require_once(__DIR__ . '/../library/' . strtolower($className) . '.class.php');
    }
    else if (file_exists(__DIR__ . '/../application/controllers/' . strtolower($className) . '.php')) 
    {
        require_once(__DIR__ . '/../application/controllers/' . strtolower($className) . '.php');
    }
    else if (file_exists(__DIR__ . '/../application/models/' . strtolower($className) . '.php')) 
    {
        require_once(__DIR__ . '/../application/models/' . strtolower($className) . '.php');
    }
}
于 2013-01-05T11:47:43.177 回答
0

只需在 header.php 或其他一些常见文件中的其他位置包含一些内容。,

<?php
$filename = basename($_SERVER['SCRIPT_FILENAME']);
$request = basename($_SERVER['SCRIPT_NAME']);

if($filename != $request)
  die('Case of filename and request do not match!');
?>

我认为这可以帮助您解决问题。另请参阅以下位置https://superuser.com/questions/431342/linux-both-case-sensitive-and-case-insensitive-and-always-inconvenient

于 2013-01-05T12:28:04.217 回答