PHP路径大小写敏感的问题

发布于 2024-12-12 22:15:51 字数 411 浏览 2 评论 0原文

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

从那时起 - 出现了一个问题:

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

我怎样才能使 PHP/Apache 表现得更好,并在其他情况下进行搜索?

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

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

I am running a SocialEngine PHP application, which i've recently migrated to another server.

And from that point on - a problem occurs:

The SocialEngine's core trying to include files in case insensitive paths,
which appear not to exist (although, in the right case, they do exist)

How can I make the PHP/Apache act nicer, and also search in other cases?

For example, the SocialEngine looks for /application/modules/Menuitems.php,
and the right path is /application/modules/Menu**I**tems.php.

To sum up: I want case-insensitive paths!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

梨涡少年 2024-12-19 22:15:51

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

You have case insensitive paths in windows. But when you move your page to linux path will be case sensitive. You can make function for build path that convert all letters to uppercase or lowercase (often preferred) and use one of these normalized naming styles for directory- and file- names.

蔚蓝源自深海 2024-12-19 22:15:51

你可以用这个代码进行实验,我只留下了几个 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'; 
?>

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

You can experiment with this code I have left only a couple of TODO steps (sorry! have no time.. and it is too big to put it as a comment) you can complete. You put this code at the very begining of the index.php file and every time an include fails the correctFile name is called.

You have to test it separately though as it gets the file name from the warning that php returns. My php version return the file name in parentheses don't know yours. Test the code to see how it works.

<?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'; 
?>

Also the code makes the assumption that the directory part-name is correct! otherwise you have to mnage that too.

花期渐远 2024-12-19 22:15:51

正如上面的评论中已经讨论过的(如果您感到被冒犯,我很抱歉,我不是那个意思)和 给出的答案存在一个根本问题:

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

这很难解决。不过我有以下想法: PHP StreamWrapper

流包装器在文件名和底层代码之间进行互操作。它们可以使用相同的接口访问 URL 和文件,例如 includefile_get_contents

通常,流的类型(并且您可以在其上注册自己的包装器)以诸如 protocol:// 之类的内容开头。

如果未给出协议,则为 file://

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

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

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

As already talked about in the comments (I'm sorry if you felt offended, was not meant that way) above and the one given answer there is a fundamental problem:

The filenames the application is using are invalid. They were not on your windows system, but they are on linux.

This is hard to solve. However I had the following idea: PHP StreamWrapper.

Stream Wrappers interoperate between filenames and the underlying code. They enable to access URLs and files with the same interface, e.g. include or file_get_contents.

Normally the type of stream (and onto which you can register your own wrapper) start with something like protocol://.

If no protocol is given, it is file://.

So what you can try is to create your own stream-wrapper that registers onto the file:// protocol. You can then deal with the problems of the case-sensitivity.

The manual provides a pre-made definition of a stream-wrapper-class you might want to re-use.

Others have given hints and code how to resolve case-sensitivity problems. You normally only need to deal with read operations in your case.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文