1

我正在运行一个SocialEngine PHP 应用程序,我最近已将其迁移到另一台服务器。

从那时起 - 出现问题:

SocialEngine 的核心试图在不区分大小写的路径中包含文件,这些路径似乎不存在(尽管在正确的情况下,它们确实存在)

如何让 PHP/Apache 表现得更好,并在其他情况下进行搜索?

例如,SocialEngine 寻找/application/modules/Menuitems.php,正确的路径是/application/modules/Menu**I**tems.php

总结一下:我想要不区分大小写的路径!

4

3 回答 3

4

您在 Windows 中有不区分大小写的路径。但是当您将页面移动到 linux 路径时,将区分大小写。您可以为构建路径创建函数,将所有字母转换为大写或小写(通常是首选),并为目录名和文件名使用这些规范化命名样式之一。

于 2011-10-31T00:03:55.327 回答
0

你可以试验这段代码,我只留下了几个 TODO 步骤(对不起!没有时间......而且它太大了,不能作为评论)你可以完成。您将此代码放在 index.php 文件的开头,每次包含失败时都会调用正确的文件名。

您必须单独测试它,因为它从 php 返回的警告中获取文件名。我的 php 版本返回括号中的文件名不知道你的。测试代码,看看它是如何工作的。

<?PHP
/*****************put this at the very top*********************************/
 $flag=2; 
 function correctFileName($incorrectFileName)
 {
    //directory and file to look at/for
    $dirToLookAt = dirname($incorrectFileName);
    $fileToLookFor = basename($incorrectFileName);

    //get all .php files
    $files = array(); $directory = opendir($dirToLookAt ); 
    while($item = readdir($directory)) 
        if(is_string(strstr($item,'.php')))
            $files[] = $item; 

    //to do
    /*
    loop through the $files array and to 
    a case insensitive search for $incorrectFileName

    if you find one then rename the file you found to $incorrectFileName

    then break the loop
    */

 }
//error handler function
function customError($errno, $errstr)
  {
        global $flag;
        //find the file name
        if($errno==2 and (($flag%2)==0))
        {
              //this will allow to enter only once per time
              $flag++;
              //get the file name
             $start = strpos($errstr, '(') +1;//7
             $length = strpos($errstr, ')') -  $start ;//10
             correctFileName(substr($errstr, $start  ,$length));
        }
  }

//set error handler
set_error_handler("customError");
/*****************************************************************/

//trigger error
include 'c:\www\home\122221.php'; 
?>

代码还假设目录部分名称是正确的!否则你也必须管理它。

于 2011-10-31T00:38:27.560 回答
0

正如上面的评论中已经谈到的(如果你感到被冒犯了,我很抱歉,不是那个意思),并且给出的答案是一个基本问题:

应用程序使用的文件名无效。它们不在您的 Windows 系统上,但它们在 linux 上。

这很难解决。但是我有以下想法:PHPStreamWrapper

流包装器在文件名和底层代码之间进行互操作。它们可以访问具有相同界面的 URL 和文件,例如includefile_get_contents.

通常流的类型(以及您可以在其上注册自己的包装器)以protocol://.

如果没有给出协议,它是file://.

因此,您可以尝试创建自己的注册file://协议的流包装器。然后,您可以处理区分大小写的问题。

该手册提供了您可能想要重用的流包装类的预制定义。

其他人给出了如何解决区分大小写问题的提示和代码。您通常只需要在您的情况下处理读取操作。

于 2011-10-31T11:48:34.443 回答