通过PHP在Windows上包含区分大小写的文件

时间:2022-04-06 07:17:56

We have an issue using the PEAR libraries on Windows from PHP.

我们在PHP上使用Windows上的PEAR库时遇到问题。

Pear contains many classes, we are making use of a fair few, one of which is the Mail class found in Mail.php. We use PEAR on the path, rather than providing the full explicit path to individual PEAR files:

Pear包含很多类,我们正在使用一些,其中一个是Mail.php中的Mail类。我们在路径上使用PEAR,而不是提供单个PEAR文件的完整显式路径:

require_once('Mail.php');

Rather than:

require_once('/path/to/pear/Mail.php');

This causes issues in the administration module of the site, where there is a mail.php file (used to send mails to users). If we are in an administrative screen that sends an email (such as the user administration screen that can generate and email new random passwords to users when they are approved from the moderation queue) and we attempt to include Mail.php we "accidentally" include mail.php.

这会导致站点的管理模块出现问题,其中有mail.php文件(用于向用户发送邮件)。如果我们在管理屏幕中发送电子邮件(例如用户管理屏幕,当用户从审核队列中获得批准时可以生成并向用户发送新的随机密码)并且我们尝试包含Mail.php,我们“意外”包括mail.php。

Without changing to prepend the full path to the PEAR install explicitly requiring the PEAR modules (non-standard, typically you install PEAR to your path...) is there a way to enforce PHP on Windows to require files case-sensitively?

无需更改前面的PEAR安装的完整路径,明确要求PEAR模块(非标准,通常是将PEAR安装到您的路径......)是否有办法在Windows上强制执行PHP以区分大小写需要文件?

We are adding the PEAR path to the include path ourselves, so have control over the path order. We also recognize that we should avoid using filenames that * with PEAR names regardless of case, and in the future will do so. This page however (which is not an include file, but a controller), has been in the repository for some years, and plugins specifically generate URLS to provide links/redirects to this page in their processing.

我们自己将PEAR路径添加到包含路径,因此可以控制路径顺序。我们还认识到,无论如何都应避免使用与PEAR名称冲突的文件名,并且将来会这样做。然而,该页面(不是包含文件,但是控制器)已经在存储库中存在了几年,并且插件专门生成URLS以在其处理中提供到该页面的链接/重定向。

(We support Apache, Microsoft IIS, LightHTTPD and Zeus, using PHP 4.3 or later (including PHP5))

(我们支持Apache,Microsoft IIS,LightHTTPD和Zeus,使用PHP 4.3或更高版本(包括PHP5))

4 个解决方案

#1


1  

having 2 files with the same name in the include path is not a good idea, rename your files so the files that you wrote have different names from third party libraries. anyway for your current situation I think by changing the order of paths in your include path, you can fix this. PHP searches for the files in the include paths, one by one. when the required file is found in the include path, PHP will stop searching for the file. so in the administration section of your application, if you want to include the PEAR Mail file, instead of the mail.php that you wrote, change your include path so the PEAR path is before the current directory. do something like this:

在包含路径中有2个具有相同名称的文件不是一个好主意,重命名您的文件,以便您编写的文件具有与第三方库不同的名称。无论如何,对于您目前的情况,我认为通过更改包含路径中的路径顺序,您可以解决此问题。 PHP逐个搜索包含路径中的文件。当在包含路径中找到所需文件时,PHP将停止搜索该文件。因此,在应用程序的管理部分中,如果要包含PEAR Mail文件而不是您编写的mail.php,请更改包含路径,以使PEAR路径位于当前目录之前。做这样的事情:

<?php
  $path_to_pear = '/usr/share/php/pear';
  set_include_path( $path_to_pear . PATH_SEPARATOR . get_include_path() );
?>

#2


3  

As it's an OS level thing, I don't believe there's an easy way of doing this.

由于这是一个操作系统级别的事情,我不相信有一个简单的方法来做到这一点。

You could try changing your include from include('Mail.php'); to include('./Mail.php');, but I'm not certain if that'll work on a Windows box (not having one with PHP to test on).

您可以尝试更改include中的include('Mail.php');包括('./ Mail.php');,但我不确定它是否适用于Windows机箱(没有用于测试的PHP)。

#3


0  

If you are using PHP 4, you can take advantage of this bug. Off course that is a messy solution...

如果您使用的是PHP 4,则可以利用此错误。当然这是一个混乱的解决方案......

Or you could just rename your mail.php file to something else...

或者您可以将mail.php文件重命名为其他内容...

#4


0  

I'm fairly certain this problem is caused by the NTFS code in the Win32 subsystem. If you use an Ext2 Installable File System (IFS), you should get case sensitivity on that drive.

我很确定这个问题是由Win32子系统中的NTFS代码引起的。如果您使用Ext2可安装文件系统(IFS),您应该在该驱动器上获得区分大小写。

#1


1  

having 2 files with the same name in the include path is not a good idea, rename your files so the files that you wrote have different names from third party libraries. anyway for your current situation I think by changing the order of paths in your include path, you can fix this. PHP searches for the files in the include paths, one by one. when the required file is found in the include path, PHP will stop searching for the file. so in the administration section of your application, if you want to include the PEAR Mail file, instead of the mail.php that you wrote, change your include path so the PEAR path is before the current directory. do something like this:

在包含路径中有2个具有相同名称的文件不是一个好主意,重命名您的文件,以便您编写的文件具有与第三方库不同的名称。无论如何,对于您目前的情况,我认为通过更改包含路径中的路径顺序,您可以解决此问题。 PHP逐个搜索包含路径中的文件。当在包含路径中找到所需文件时,PHP将停止搜索该文件。因此,在应用程序的管理部分中,如果要包含PEAR Mail文件而不是您编写的mail.php,请更改包含路径,以使PEAR路径位于当前目录之前。做这样的事情:

<?php
  $path_to_pear = '/usr/share/php/pear';
  set_include_path( $path_to_pear . PATH_SEPARATOR . get_include_path() );
?>

#2


3  

As it's an OS level thing, I don't believe there's an easy way of doing this.

由于这是一个操作系统级别的事情,我不相信有一个简单的方法来做到这一点。

You could try changing your include from include('Mail.php'); to include('./Mail.php');, but I'm not certain if that'll work on a Windows box (not having one with PHP to test on).

您可以尝试更改include中的include('Mail.php');包括('./ Mail.php');,但我不确定它是否适用于Windows机箱(没有用于测试的PHP)。

#3


0  

If you are using PHP 4, you can take advantage of this bug. Off course that is a messy solution...

如果您使用的是PHP 4,则可以利用此错误。当然这是一个混乱的解决方案......

Or you could just rename your mail.php file to something else...

或者您可以将mail.php文件重命名为其他内容...

#4


0  

I'm fairly certain this problem is caused by the NTFS code in the Win32 subsystem. If you use an Ext2 Installable File System (IFS), you should get case sensitivity on that drive.

我很确定这个问题是由Win32子系统中的NTFS代码引起的。如果您使用Ext2可安装文件系统(IFS),您应该在该驱动器上获得区分大小写。